diff --git a/app/src/main/java/app/suhasdissa/memerize/ui/screens/secondary/VideoView.kt b/app/src/main/java/app/suhasdissa/memerize/ui/screens/secondary/VideoView.kt index b111fc5..64d488c 100644 --- a/app/src/main/java/app/suhasdissa/memerize/ui/screens/secondary/VideoView.kt +++ b/app/src/main/java/app/suhasdissa/memerize/ui/screens/secondary/VideoView.kt @@ -47,11 +47,14 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.compose.ui.platform.LocalView import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.viewinterop.AndroidView +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LifecycleEventObserver import androidx.lifecycle.viewmodel.compose.viewModel import androidx.media3.common.MediaItem import androidx.media3.common.Player @@ -87,6 +90,21 @@ fun VideoView( view.keepScreenOn = false } } + val lifecycleOwner = LocalLifecycleOwner.current + + DisposableEffect(lifecycleOwner) { + val observer = LifecycleEventObserver { _, event -> + if (event == Lifecycle.Event.ON_STOP) { + player.pause() + } + } + + lifecycleOwner.lifecycle.addObserver(observer) + + onDispose { + lifecycleOwner.lifecycle.removeObserver(observer) + } + } DisposableEffect(Unit) { with(player) { val mediaItem = MediaItem.Builder().setUri(meme.url).build()