Reputation: 631
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).
Upvotes: 40
Views: 63697
Reputation: 2541
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)
Upvotes: 9
Reputation: 4528
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
Upvotes: 4
Reputation: 6690
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
Upvotes: 9
Reputation: 419
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.
Upvotes: 1
Reputation: 57
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
Upvotes: -9
Reputation: 1025
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
Upvotes: 22
Reputation: 468
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.
Upvotes: 30