androidandroid-studiolibvlcunsatisfiedlinkerror

Playing a YouTube video in a android application using LibVLC


I am just trying to make an simple android application which will play a video from YouTube which I provide as a link. Here is the code

package com.example.videoplayer;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.VideoView;

import org.videolan.libvlc.IVLCVout;
import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.Media;
import org.videolan.libvlc.MediaPlayer;

import java.util.ArrayList;
import java.util.logging.StreamHandler;

public class MainActivity extends AppCompatActivity {

private static String TAG = "MainActivity";
private VideoView vv;
private Button bt;

private Context mContext = this;

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    vv = findViewById(R.id.videoView);
    bt = findViewById(R.id.button);

}

public void setUpMediaStream(View view) {
    final ArrayList<String> args = new ArrayList<>();
    args.add("-vvv");
    mLibVLC = new LibVLC(mContext, args);
    Log.d(TAG, "setUpMediaStream() creating media player");
    mMediaPlayer = new MediaPlayer(mLibVLC);
    Log.d(TAG, "setUpMediaStream() setting video view");
    String yt = "https://www.youtube.com/watch?v=tXHoqsnRD-U";
    Media media = new Media(mLibVLC, Uri.parse(yt));

    mMediaPlayer.setMedia(media);
    media.release();

    mMediaPlayer.setAspectRatio(null);
    mMediaPlayer.setScale(0);
    Log.d(TAG, "setUpMediaStream() playing media");
    mMediaPlayer.play();
}}

The problem is I am facing the following exception when I press the play button java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.videoplayer-JGI3RJow0fmaB6c-w2WuVQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.videoplayer-JGI3RJow0fmaB6c-w2WuVQ==/lib/arm64, /system/lib64]]] couldn't find "libc++_shared.so"

Any response is helpful.

Here is my XML :

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<VideoView
    android:id="@+id/videoView"
    android:layout_width="370dp"
    android:layout_height="390dp"
    android:layout_marginTop="104dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.487"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="72dp"
    android:onClick="setUpMediaStream"
    android:text="@string/play"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.498"`enter code here`
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/videoView"
    app:layout_constraintVertical_bias="0.153" /> </androidx.constraintlayout.widget.ConstraintLayout>

Solution

  • I was unable to replicate your exception, but...

    I don't think you can just pass in a url of a web page, vlc is not a WebView - it needs to be a playable file, such as https://jell.yfish.us/media/jellyfish-3-mbps-hd-h264.mkv - and be sure to add the internet permission in the manifest:

    <uses-permission android:name="android.permission.INTERNET" />
    

    I also think you need to replace the VideoView in your layout with org.videolan.libvlc.util.VLCVideoLayout and pass it into mediaPlayer.attachViews() after you instantiate the MediaPlayer.

    I was able to play the video with these steps.

    ** EDIT **

    LibVLC also have a sample project, where in their app-level build.gradle file they specify jni directories:

    android {
    ...
        sourceSets {
            main {
                jni.srcDirs = [] // Prevent gradle from building native code with ndk; we have our own Makefile for it.
                jniLibs.srcDir 'jni/libs' // Where generated .so files are placed
                assets.srcDirs = ['src/main/assets', '../assets/']
            }
        }
    }
    

    https://code.videolan.org/videolan/libvlc-android-samples/-/tree/master/java_sample