Good Morning all. I am having a cosmetic issue wi...
# compose
m
Good Morning all. I am having a cosmetic issue with camera media3 compose (this might exist in the xml version too). If i play a video, and let the video run it's full length. Then i background the app, then foreground again, it's showing a black background over the player surface. However, when i pause the video in the middle and do the same, it shows the frame where it was paused. I would have expected that in the first case, it would just render the last frame when it came back from the background instead of a black screen.
Copy code
val player = remember {
    ExoPlayer.Builder(context).build().apply {
        setMediaItem(
            MediaItem.fromUri(url)
        )
        prepare()
    }
}

PlayerSurface(
    player = player,
    modifier = sizeModifier
)
n
If you're using
SurfaceView
behind the scenes, try switching to
TextureView
, which retains the surface in the background.
In your Composable, if you're using a custom
PlayerSurface
, ensure it's using
TextureView
AndroidView( factory = { PlayerView(it).apply { player = exoPlayer useTextureView = true } }, modifier = Modifier.fillMaxSize() )
m
Thanks.
n
playerView.keepContentOnPlayerReset = true
val lifecycleOwner = LocalLifecycleOwner.current DisposableEffect(Unit) { val observer = LifecycleEventObserver { _, event -> when (event) { Lifecycle.Event.ON_PAUSE -> player.playWhenReady = false Lifecycle.Event.ON_RESUME -> player.playWhenReady = true else -> {} } } lifecycleOwner.lifecycle.addObserver(observer) onDispose { lifecycleOwner.lifecycle.removeObserver(observer) player.release() } }