fix: preserve start position and subtitles in ExoPlayer→MPV fallback

This commit is contained in:
edde746
2026-03-15 11:32:25 +01:00
parent 360c3356cf
commit 0100b2a2ea
6 changed files with 44 additions and 27 deletions
@@ -143,6 +143,8 @@ class ExoPlayerCore(private val activity: Activity) : Player.Listener {
// Track state for event emission
private var lastPosition: Long = 0
/** Position to use for fallback: max of current position and pending start position. */
private val effectivePosition: Long get() = maxOf(lastPosition, pendingStartPositionMs)
private var lastDuration: Long = 0
private var lastBufferedPosition: Long = 0
private var positionUpdateRunnable: Runnable? = null
@@ -645,7 +647,7 @@ class ExoPlayerCore(private val activity: Activity) : Player.Listener {
delegate?.onFormatUnsupported(
uri = currentMediaUri!!,
headers = currentHeaders,
positionMs = lastPosition,
positionMs = effectivePosition,
errorMessage = "Video track present but no decoder available"
)
return
@@ -671,7 +673,7 @@ class ExoPlayerCore(private val activity: Activity) : Player.Listener {
val handled = delegate?.onFormatUnsupported(
uri = currentMediaUri!!,
headers = currentHeaders,
positionMs = lastPosition,
positionMs = effectivePosition,
errorMessage = error.message ?: "Unknown error"
) ?: false
@@ -1069,7 +1071,7 @@ class ExoPlayerCore(private val activity: Activity) : Player.Listener {
delegate?.onFormatUnsupported(
uri = uri,
headers = currentHeaders,
positionMs = lastPosition,
positionMs = effectivePosition,
errorMessage = "Decoder hang: $decoderName accepted input but produced no output"
)
}
@@ -211,8 +211,11 @@ class ExoPlayerPlugin : FlutterPlugin, MethodChannel.MethodCallHandler,
return
}
// New media = fresh slate for pending MPV properties
pendingMpvProperties.clear()
// Only clear pending MPV properties when MPV is the active backend.
// When ExoPlayer is active, keep them for potential ExoPlayer→MPV fallback.
if (usingMpvFallback) {
pendingMpvProperties.clear()
}
activity?.runOnUiThread {
if (usingMpvFallback) {