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)