From 0bfd0869171dc33fe5f1556ffbe1c401989b031e Mon Sep 17 00:00:00 2001 From: VenusIsJaded Date: Mon, 22 Jun 2026 07:16:03 -0500 Subject: [PATCH] fix: ExoPlayer unpausing when leaving the app and coming back The LifecycleEventObserver was only capturing playWhenReady at the time the effect ran. When ON_START fired later, it would use the old value and resume playback even if the user had paused before leaving the app. Use rememberUpdatedState so we always read the live value. Fixes #1080 --- .../com/nuvio/app/features/player/PlayerEngine.android.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/composeApp/src/androidMain/kotlin/com/nuvio/app/features/player/PlayerEngine.android.kt b/composeApp/src/androidMain/kotlin/com/nuvio/app/features/player/PlayerEngine.android.kt index 3ec9539c..97911e9c 100644 --- a/composeApp/src/androidMain/kotlin/com/nuvio/app/features/player/PlayerEngine.android.kt +++ b/composeApp/src/androidMain/kotlin/com/nuvio/app/features/player/PlayerEngine.android.kt @@ -90,6 +90,7 @@ actual fun PlatformPlayerSurface( val lifecycleOwner = LocalLifecycleOwner.current val latestOnSnapshot = rememberUpdatedState(onSnapshot) val latestOnError = rememberUpdatedState(onError) + val latestPlayWhenReady = rememberUpdatedState(playWhenReady) val coroutineScope = rememberCoroutineScope() val playerSettings = remember { @@ -385,7 +386,7 @@ actual fun PlatformPlayerSurface( val activity = context.findActivity() val observer = LifecycleEventObserver { _, event -> when (event) { - Lifecycle.Event.ON_START -> exoPlayer.playWhenReady = playWhenReady + Lifecycle.Event.ON_START -> exoPlayer.playWhenReady = latestPlayWhenReady.value Lifecycle.Event.ON_STOP -> { val isInPictureInPicture = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && activity?.isInPictureInPictureMode == true @@ -405,7 +406,7 @@ actual fun PlatformPlayerSurface( } LaunchedEffect(exoPlayer, playWhenReady) { - exoPlayer.playWhenReady = playWhenReady + exoPlayer.playWhenReady = latestPlayWhenReady.value syncPlayerViewKeepScreenOn() latestOnSnapshot.value(exoPlayer.snapshot()) }