如何使用libvlc-all:3.2.0在android应用中播放youtube视频?

问题描述 投票:0回答:1

我正在创建一个Android播放器来播放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. 如果提供其他任何流式传输网址(hls),则可以正常运行。但是YouTube视频不走运。

有人可以帮助解决吗?

java android youtube libvlc vlc-android
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.