gpt4 book ai didi

java - 如何使用 libvlc-all :3. 2.0 在 Android 应用程序中播放 YouTube 视频?

转载 作者:行者123 更新时间:2023-12-02 09:21:19 26 4
gpt4 key购买 nike

我正在创建一个 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。 Activity 课

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();
  • 等级文件

  • repositories {
    google()
    maven {
    url "https://dl.bintray.com/videolan/Android"
    }
    jcenter()
    }
    dependencies {
    implementation 'org.videolan.android:libvlc-all:3.2.0'
    }
  • 如果我们提供任何其他流媒体网址 (hls),它就可以工作。但 YouTube 视频就不那么幸运了。
  • 谁能帮忙解决一下吗?

    最佳答案

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

    关于java - 如何使用 libvlc-all :3. 2.0 在 Android 应用程序中播放 YouTube 视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58674469/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com