fix(player): refresh Android MPV decoder on startup

This commit is contained in:
edde746
2026-05-09 05:10:51 +02:00
parent c38c0cf55d
commit 3e6ebcdb6a
4 changed files with 90 additions and 27 deletions
@@ -693,13 +693,20 @@ class MpvPlayerCore(private val activity: Activity) : SurfaceHolder.Callback {
p.observeProperty(name, fmt)
}
fun command(args: Array<String>) {
if (!isInitialized || disposing || args.isEmpty()) return
fun command(args: Array<String>, onComplete: ((Boolean) -> Unit)? = null) {
if (!isInitialized || disposing || args.isEmpty() || !scope.isActive) {
onComplete?.invoke(false)
return
}
scope.launch {
var success = false
try {
player?.command(*args)
success = true
} catch (e: Exception) {
Log.w(TAG, "command failed", e)
} finally {
onComplete?.invoke(success)
}
}
}
@@ -271,8 +271,14 @@ class MpvPlayerPlugin :
return
}
playerCore?.command(args.toTypedArray())
result.success(null)
val core = playerCore
if (core == null) {
result.success(null)
return
}
core.command(args.toTypedArray()) {
result.success(null)
}
}
private fun handleSetVisible(call: MethodCall, result: MethodChannel.Result) {