fix(android): preserve display mode across backend fallback

This commit is contained in:
edde746
2026-05-04 01:19:32 +02:00
parent aa6e9648bb
commit bf89925d6a
3 changed files with 22 additions and 3 deletions
@@ -1905,7 +1905,12 @@ class ExoPlayerCore(private val activity: Activity) : Player.Listener {
cancelDecoderHangCheck()
stopPositionUpdates()
handler.removeCallbacksAndMessages(null)
frameRateManager?.clearVideoFrameRate()
// releasePending (not clearVideoFrameRate): on the ExoPlayer→MPV fallback
// path, dispose runs after the rate switch has been applied — clearing
// preferredDisplayModeId here would renegotiate HDMI back to default
// before MPV's surface comes up. Explicit user-leave still calls
// clearVideoFrameRate via Dart (video_player_screen.dart).
frameRateManager?.releasePending()
frameRateManager = null
audioFocusManager?.release()
audioFocusManager = null
@@ -767,8 +767,11 @@ class MpvPlayerCore(private val activity: Activity) : SurfaceHolder.Callback {
handler.removeCallbacksAndMessages(null)
// Clean up frame rate and audio focus
frameRateManager?.clearVideoFrameRate()
// Clean up frame rate and audio focus.
// releasePending (not clearVideoFrameRate): symmetric with ExoPlayerCore —
// dispose only releases the listener/pending future. Restoring the
// display mode is the explicit Dart-side clearVideoFrameRate's job.
frameRateManager?.releasePending()
frameRateManager = null
audioFocusManager?.release()
audioFocusManager = null
@@ -90,6 +90,17 @@ class FrameRateManager(
}
}
// Release pending callbacks/listener without restoring the display mode.
// Used by player-core dispose paths so a backend handoff (e.g. ExoPlayer→MPV
// audio fallback) doesn't clobber the just-applied refresh-rate switch —
// window-scoped preferredDisplayModeId persists across the SurfaceView swap,
// letting MPV inherit the rate without a second HDMI renegotiation.
fun releasePending() {
Log.d(TAG, "releasePending")
currentVideoFps = 0f
firePendingCompletion("release", switched = false)
}
private fun cancelPendingCallbacks() {
pendingSettleRunnable?.let { handler.removeCallbacks(it) }
watchdogRunnable?.let { handler.removeCallbacks(it) }