How to play youtube videos in android app using libvlc-all:3.2.0?

2.9k Views Asked by At

I was creating an android player to play youtube live streams. My requirement is to play the stream in VLC org.videolan.libvlc.util.VLCVideoLayout. I followed the sample aplication https://code.videolan.org/videolan/libvlc-android-samples. When I tried to play youtube videos, it is not playing but only blank screen.

I used the following code.

1. In layout xml file

<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. In activity class

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. gradel file

repositories {
    google()
    maven {
        url "https://dl.bintray.com/videolan/Android"
    }
    jcenter()
}
dependencies {
    implementation 'org.videolan.android:libvlc-all:3.2.0'
}
  1. If we give any other streaming url (hls), it works. But no luck with youtube videos.

Could anyone help to solve it ?

1

There are 1 best solutions below

3
On

For youtube videos, you have to parse the media and then play one of its sub items.