import android.app.Activity import android.os.Bundle import io.github.kmpmpv.MpvConfiguration import io.github.kmpmpv.MpvPlayer import io.github.kmpmpv.MpvSurfaceView import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.cancel import kotlinx.coroutines.launch class PlayerActivity : Activity() { private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate) private lateinit var player: MpvPlayer private lateinit var video: MpvSurfaceView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) player = MpvPlayer.create( MpvConfiguration( options = MpvConfiguration.DefaultOptions + mapOf("hwdec" to "mediacodec-copy"), ), ) video = MpvSurfaceView(this).apply { bind(player) } setContentView(video) scope.launch { player.load(intent.data.toString()) } } override fun onDestroy() { video.dispose() scope.launch { player.release() scope.cancel() } super.onDestroy() } }