Yokan / rebuild
Course 1 8624561

MpvActivitySnippet.kt

vendor/kmp-mpv/samples/android/MpvActivitySnippet.kt

implementation37 lines
1import android.app.Activity2import android.os.Bundle3import io.github.kmpmpv.MpvConfiguration4import io.github.kmpmpv.MpvPlayer5import io.github.kmpmpv.MpvSurfaceView6import kotlinx.coroutines.CoroutineScope7import kotlinx.coroutines.Dispatchers8import kotlinx.coroutines.SupervisorJob9import kotlinx.coroutines.cancel10import kotlinx.coroutines.launch1112class PlayerActivity : Activity() {13    private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)14    private lateinit var player: MpvPlayer15    private lateinit var video: MpvSurfaceView1617    override fun onCreate(savedInstanceState: Bundle?) {18        super.onCreate(savedInstanceState)19        player = MpvPlayer.create(20            MpvConfiguration(21                options = MpvConfiguration.DefaultOptions + mapOf("hwdec" to "mediacodec-copy"),22            ),23        )24        video = MpvSurfaceView(this).apply { bind(player) }25        setContentView(video)26        scope.launch { player.load(intent.data.toString()) }27    }2829    override fun onDestroy() {30        video.dispose()31        scope.launch {32            player.release()33            scope.cancel()34        }35        super.onDestroy()36    }37}38

Search chapters, reference and source filenames.