A library version of mpv-android, providing libmpv for Android applications. Initially made for mpvKt.
- Multiple MPV instances
mpv_nodesupport- DASH support
Add the dependency to your build.gradle:
dependencies {
implementation "io.github.abdallahmehiz:mpv-android-lib:<version>"
}The simplest way to extend BaseMPVView:
class MyPlayerView(context: Context, attrs: AttributeSet?) : BaseMPVView(context, attrs) {
override fun initOptions() {
// Set options before mpv.init() is called
mpv.setOptionString("hwdec", "auto")
}
override fun postInitOptions() {
// Set options after mpv.init() is called
mpv.setOptionString("sub-auto", "fuzzy")
}
}
val playerView = MyPlayerView(context, null)
playerView.initialize(configDir = filesDir.path, cacheDir = cacheDir.path)
playerView.playFile("/path/to/video.mp4")You can also use MPV() then attach to fully control your mpv instance.
val mpv = MPV()
mpv.create(context)
mpv.setOptionString("config", "yes")
mpv.init()
// Attach to a view surface
mpv.attachSurface(surface)
// Load and play a file
mpv.command("loadfile", "/path/to/video.mp4")
// Access props
val paused: Boolean? = mpv.prop["pause"]
mpv.prop["pause"] = false
// access and set nodes
val node: MPVNode? = mpv.getPropertyNode("track-list")
mpv.setPropertyNode("chapter-list", myCustomChaptersList)
// observe as kotlin flows
val pauseState: StateFlow<Boolean?> = mpv.propFlow["pause"]
// cleanup
mpv.detachSurface()
mpv.destroy()Each MPV() or BaseMPVView instance is independent:
val player1 = MPV()
val player2 = MPV()
player1.create(context)
player2.create(context)
// Each player can play different content simultaneouslyTake a look at the README inside the buildscripts directory.
Some other documentation can be found at this link.