Skip to content

org.videolan.libvlc.MediaPlayer use textview to display video will cause crash

org.videolan.libvlc.MediaPlayer display video with textureview will cause crash

Description

the vlc library i am using is org.videolan.android:libvlc-all:3.3.0-eap12

I want display video with textureview ,so I use following codes to config vlc mediaplayer

private static final boolean USE_TEXTURE_VIEW = true;
private static final boolean ENABLE_SUBTITLES = true;
...
mMediaPlayer.attachViews(mVideoLayout, null, ENABLE_SUBTITLES, USE_TEXTURE_VIEW);

Actual behavior

App crash with following exception

FATAL EXCEPTION: main
    Process: org.videolan.java_sample, PID: 13930
    java.lang.RuntimeException: Unable to start activity ComponentInfo{org.videolan.java_sample/org.videolan.javasample.JavaActivity}: java.lang.IllegalArgumentException: surfaceTexture must not be null
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6944)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
     Caused by: java.lang.IllegalArgumentException: surfaceTexture must not be null
        at android.view.Surface.<init>(Surface.java:194)
        at org.videolan.libvlc.AWindow$SurfaceHelper.attachTextureView(AWindow.java:99)
        at org.videolan.libvlc.AWindow$SurfaceHelper.attach(AWindow.java:112)
        at org.videolan.libvlc.AWindow.attachViews(AWindow.java:327)
        at org.videolan.libvlc.VideoHelper.attachViews(VideoHelper.java:97)
        at org.videolan.libvlc.MediaPlayer.attachViews(MediaPlayer.java:628)
        at org.videolan.javasample.JavaActivity.onStart(JavaActivity.java:61)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1340)
        at android.app.Activity.performStart(Activity.java:7200)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2920)

Context

vlc library version

org.videolan.android:libvlc-all:3.3.0-eap12

full java code

public class JavaActivity extends AppCompatActivity  {
    private static final boolean USE_TEXTURE_VIEW = true;
    private static final boolean ENABLE_SUBTITLES = true;
    private static final String ASSET_FILENAME = "bbb.m4v";

    private VLCVideoLayout mVideoLayout = null;

    private LibVLC mLibVLC = null;
    private MediaPlayer mMediaPlayer = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        final ArrayList<String> args = new ArrayList<>();
        args.add("-vvv");
        mLibVLC = new LibVLC(this, args);
        mMediaPlayer = new MediaPlayer(mLibVLC);

        mVideoLayout = findViewById(R.id.video_layout);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mMediaPlayer.release();
        mLibVLC.release();
    }

    @Override
    protected void onStart() {
        super.onStart();

        mMediaPlayer.attachViews(mVideoLayout, null, ENABLE_SUBTITLES, USE_TEXTURE_VIEW);

        try {
            final Media media = new Media(mLibVLC, getAssets().openFd(ASSET_FILENAME));
            mMediaPlayer.setMedia(media);
            media.release();
        } catch (IOException e) {
            throw new RuntimeException("Invalid asset folder");
        }
        mMediaPlayer.play();
    }

    @Override
    protected void onStop() {
        super.onStop();

        mMediaPlayer.stop();
        mMediaPlayer.detachViews();
    }
}

layout xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true">


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


</RelativeLayout>

Android version

Android 8.0.0

Device model

galaxy s7 edge

App mode

Smartphone