Skip to content

Secozzi/mpv-android

 
 

Repository files navigation

THIS DOESN'T WORK WITHOUT ANIYOMI-FFMPEG-KIT

mpv for Animiru

Build Status Maven Central

A library version of mpv-android, providing libmpv for Android applications. Initially made for mpvKt.

"New" Features

  • Multiple MPV instances
  • mpv_node support
  • DASH support

Installation

Add the dependency to your build.gradle:

dependencies {
    implementation "io.github.abdallahmehiz:mpv-android-lib:<version>"
}

Getting Started

Using BaseMPVView

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")

Using MPV() Directly

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()

Multiple Instances

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 simultaneously

Building from source

Take a look at the README inside the buildscripts directory.

Some other documentation can be found at this link.

About

#mpv-android @ libera.chat

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Kotlin 38.3%
  • C++ 33.9%
  • Shell 22.4%
  • Makefile 2.2%
  • C 2.1%
  • Dockerfile 1.1%