【问题标题】:How to play youtube videos in android app using libvlc-all:3.2.0?如何使用 libvlc-all:3.2.0 在 android 应用程序中播放 youtube 视频?
【发布时间】:2020-02-28 15:36:40
【问题描述】:

我正在创建一个安卓播放器来播放 youtube 直播。我的要求是在 VLC org.videolan.libvlc.util.VLCVideoLayout 中播放流。 我遵循了示例应用程序https://code.videolan.org/videolan/libvlc-android-samples。 当我尝试播放 youtube 视频时,它没有播放,只是空白屏幕。

我使用了以下代码。

1.在布局xml文件中

<org.videolan.libvlc.util.VLCVideoLayout
        android:id="@+id/vlc_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:keepScreenOn="true"
        android:fitsSystemWindows="false"
        />

2。在活动课中

final ArrayList<String> args = new ArrayList<>();
args.add("--no-drop-late-frames");
args.add("--no-skip-frames");
args.add("--rtsp-tcp");
args.add("-vvv");
mLibVLC = new LibVLC(this, args);
mMediaPlayer = new MediaPlayer(mLibVLC);

mVideoLayout = findViewById(R.id.vlc_layout);
mMediaPlayer.attachViews(mVideoLayout, null, ENABLE_SUBTITLES, USE_TEXTURE_VIEW);
String url = "https://www.youtube.com/watch?v=H9mXFeGsGEE";
final Media media = new Media(mLibVLC, Uri.parse(url));
mMediaPlayer.setMedia(media);
media.release();
mMediaPlayer.play();
  1. 分级文件

repositories {
    google()
    maven {
        url "https://dl.bintray.com/videolan/Android"
    }
    jcenter()
}
dependencies {
    implementation 'org.videolan.android:libvlc-all:3.2.0'
}
  1. 如果我们提供任何其他流 url (hls),它可以工作。但是 youtube 视频就没有运气了。

谁能帮忙解决?

【问题讨论】:

    标签: java android youtube libvlc vlc-android


    【解决方案1】:

    对于 youtube 视频,您必须解析媒体,然后播放其中一个子项目。

    【讨论】:

    • 如果我直接在 VLC 播放器中提供 youtube 网址,它可以工作。所以我认为libVLC 也有办法。我可以使用 youtube url 从应用程序中打开 VLC 播放器。但是 libVLC 没有运气。
    • 我刚刚告诉你用 libvlc 的方法
    猜你喜欢
    • 2021-03-16
    • 2012-07-05
    • 1970-01-01
    • 2016-11-30
    • 2011-06-06
    • 2014-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多