How to embed VLC media player to my Android App
Asked Answered
I

7

40

Is there a way to embed VLC media player to Android Application? I have several issues:

1) I have a video streaming Camera (from RTSP) and I cannot play its stream on my regular videoview panel (Sorry this video cannot be played error). However, I installed the VLC application for Android (beta version) and I was able to play it. 2) My main objective is to port a desktop java application which uses VLC plugin to Android. I want to accomplish this task with minimum effort (I have some time issues).

Another alternative, is there a way to embed codecs used by VLC to my application? Because with my videoview, the result varies according to the format of the video. I can play some other videos streamed through RTSP on my videoview.

I search through internet and found a "libvlc" but also some notes about that libvlc for android is not complete (but those notes belong to a past time, even in stackoverflow).

Implode answered 27/2, 2014 at 16:7 Comment(1)
Given that you say the VLC player app exists, you apparently have that as proof VLC can be embedded in an app... Have you tried examining the source (and license) applicable to that app?Eringo
F
30

Yes, if you already have the vlc-sdk.7z (libVLC for android), here is the sample project to embedded VLC into your android apps.

If you do not have libVLC, here are the steps to build one. (After "sh compile.sh" finished, "make vlc-sdk.7z" to create the vlc-sdk.7z and unzip to the demo project.

I put the vlc-sdk.7z(only armeabi-v7a is included) here for testing.

Forsythia answered 11/3, 2014 at 6:22 Comment(3)
Anyone know what the licensing is like for this? Is it compatible with use in a commercial app?Antlion
This lib will increase the size of apkTiger
@AshishSaini This comment will increase the size of siteLedaledah
B
22

Maruku has given a great answer.

In addition, if you don't want to compile libVLC on your own machine, mrmaffen has kindly thrown it up onto maven central. So in your .gradle file include

compile "de.mrmaffen:vlc-android-sdk:1.9.8"

Keep in mind that LibVLC may not be 100% updated because you aren't compiling the source yourself.

More info can be found here on GitHub

Border answered 30/7, 2015 at 5:57 Comment(6)
Can you pl give me some insight about api documentation , No idea how I can integrate the sdkFaggot
I'm looking for a few days to sdk3, and everything on the internet is very complicated.Amplify
I found this sample by Juanma jurado, very easy to start with. It uses libvlc3.aar library directly(no Jcenter).Saturate
Sample App from Gary Anderson uses the VLC Player from JCenter.Saturate
Watch out: NOTE: 1.9.8 is the latest version! Please ignore the old version 3.0.0. github.com/mrmaffen/vlc-android-sdk#get-it-via-maven-centralNeglectful
@saiyancoder: why 1.9.8 is the latest version (3.0.0 seems is newer)Flagella
W
9

2019 sees introduction of a VLCVideoLayout component that greatly simplifies the code required to embed VLC into android.

https://code.videolan.org/videolan/libvlc-android-samples

The libVLC is provided by the official VideoLAN project hosted on BinTray. See the build.gradle files for the link to the Maven repo and the package name/version.

https://code.videolan.org/videolan/libvlc-android-samples/blob/master/build.gradle#L18 https://code.videolan.org/videolan/libvlc-android-samples/blob/master/java_sample/build.gradle#L34

Whipstock answered 22/9, 2019 at 6:38 Comment(1)
this is great, but what about documentation?.. I didn't found any in Google, mb somebody will share?Herbalist
C
8

in build.gradle:

allprojects {
repositories {
    google()
    jcenter()
    maven {
        url 'https://jitpack.io'
    }
    maven {
        url "https://dl.bintray.com/videolan/Android"
    }
}

}

in app\build.gradle:

implementation "org.videolan.android:libvlc-all:3.1.12"

in activity_camera.xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:background="@android:color/background_dark"
    android:keepScreenOn="true"
    tools:context=".ui.main.cameras.CameraActivity">

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

</FrameLayout>

in CameraActivity.java

import android.net.Uri
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.navArgs
import com.android.forum.R
import kotlinx.android.synthetic.main.activity_camera.*
import org.videolan.libvlc.LibVLC
import org.videolan.libvlc.Media
import org.videolan.libvlc.MediaPlayer
import java.io.IOException
import java.util.*

private const val USE_TEXTURE_VIEW = false
private const val ENABLE_SUBTITLES = true

class CameraActivity : AppCompatActivity() {

    private var mLibVLC: LibVLC? = null
    private var mMediaPlayer: MediaPlayer? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_camera)
        mLibVLC = LibVLC(this, ArrayList<String>().apply {
            add("--no-drop-late-frames")
            add("--no-skip-frames")
            add("--rtsp-tcp")
            add("-vvv")
        })
        mMediaPlayer = MediaPlayer(mLibVLC)
    }

    override fun onStart() {
        super.onStart()
        mMediaPlayer?.attachViews(videoLayout, null, ENABLE_SUBTITLES, USE_TEXTURE_VIEW)

        try {
            val name = "login";
            val password = "password";
            val cameraUrl = "100.00.00.01:9982";
            val rtspUrl = "rtsp://" + name + ":" + password + "@" + cameraUrl
            val httpUrl = "https://archive.org/download/Popeye_forPresident/Popeye_forPresident_512kb.mp4"
            val uri = Uri.parse(httpUrl) // ..whatever you want url...or even file fromm asset
            
            Media(mLibVLC, uri).apply {
                setHWDecoderEnabled(true, false);
                addOption(":network-caching=150");
                addOption(":clock-jitter=0");
                addOption(":clock-synchro=0");
                mMediaPlayer?.media = this

            }.release()

            mMediaPlayer?.play()

        } catch (e: IOException) {
            e.printStackTrace()
        }
    }

    override fun onStop() {
        super.onStop()
        mMediaPlayer?.stop()
        mMediaPlayer?.detachViews()
    }

    override fun onDestroy() {
        super.onDestroy()
        mMediaPlayer?.release()
        mLibVLC?.release()
    }
}

p.s. about rtsp, in my case it works in 9982 port only(in link: rtsp://login:[email protected]:9982 while in IE link looks like: http://100.00.00.01:9981)

Chianti answered 3/7, 2020 at 14:59 Comment(2)
Best answer! +1 to bring it up. If possible, please explain the options that you added while creating objects of LibVLC and Media.Inodorous
Any documentation for this? Any java examples?Adjective
T
4

The libVLC is provided by the official VideoLAN project hosted on BinTray. You can directly use the library as a dependency without having to compile it.

add maven url "https://dl.bintray.com/videolan/Android" to your project-level Gradle file as shown below:

allprojects {
 repositories {
      google()
      jcenter()
      maven {
        url "https://maven.google.com";
        }
      maven { url "https://dl.bintray.com/videolan/Android" }
  }
}

and in your app-level Gradle file, add the libVLC dependency

implementation 'org.videolan.android:libvlc-all:<latest-version-here>'

Get the latest libVLC version from the below official VLC GitHub repository.

find the string "libvlcVersion" to get the latest version.

https://github.com/videolan/vlc-android/blob/master/build.gradle#L33

Tournedos answered 27/3, 2020 at 7:47 Comment(1)
The latest version could be found here -> github.com/videolan/vlc-android/releasesStepp
R
1

Some other answers link to outdated versions, however actual for 2019.03 is LibVlc for all platforms 3.1.8. This is .aar version, you may add it to your project with these instructions and use.

However if all-version is too large(over 70MB), here is armv7 version, and here if x86.

Rata answered 28/3, 2019 at 9:17 Comment(0)
S
-9

Step 1 : install Linux

Step 2 : install ndk and sdk

Step 3 : change your directory path upto compile.sh

then compile.sh run through your Linux terminal and generate apk

Compile - Run - Enjoy

Shavers answered 8/5, 2018 at 12:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.