compose-video
compose-video copied to clipboard
Question regarding lifecycle
Hi! Nice extension.
I was experimenting with it and found that when using m3u8 network playback stream, the handleLifecycle=true paused playback properly when leaving the app, but never resumed it when coming back, resulting in back screen.
Not sure if it is a bug or a problem on my end. Perhaps it makes sense to be able to optionally create the exoplayer instance outside the library, for having more control over the instance? I'd assume then I would be able to use it to control playback with some custom logic.
Hello @Blefish! Thanks for your question. This library provide get exoplayer instance via 'playerInstance' property. I think this is a library bug, please give your code included reproduce this issue? Thank you!
I have the same issue. After returning to the app the video is blank.
VideoPlayer(
mediaItems = listOf(VideoPlayerMediaItem.NetworkMediaItem(videoUrl)),
modifier = Modifier
.aspectRatio(aspect)
.align(Alignment.Center)
.clickable { onClick() },
controllerConfig = VideoPlayerControllerConfig.Default.copy(
showSubtitleButton = false,
showCurrentTimeAndTotalTime = false,
showBufferingProgress = true,
showBackTrackButton = false,
showNextTrackButton = false,
controllerShowTimeMilliSeconds = 0,
controllerAutoShow = false,
showFullScreenButton = false,
),
usePlayerController = false,
enablePip = false,
enablePipWhenBackPressed = false,
volume = if (videoState == VideoState.Muted) 0f else 1f,
repeatMode = RepeatMode.ALL,
handleLifecycle = true,
autoPlay = true,
)
@Blefish @dsa28s I've managed to workaround the issue by removing the view from the composition when onPause is called and adding it back in when onResume is called.
Here is the code:
var shown by remember {
mutableStateOf(false)
}
DisposableEffectWithLifeCycle(
onResume = { shown = true },
onPause = { shown = false }
)
if (shown) {
VideoPlayer(
mediaItems = listOf(VideoPlayerMediaItem.NetworkMediaItem(videoUrl)),
modifier = Modifier
.aspectRatio(aspect)
.align(Alignment.Center)
.clickable { onClick() },
controllerConfig = VideoPlayerControllerConfig.Default.copy(
showSubtitleButton = false,
showCurrentTimeAndTotalTime = false,
showBufferingProgress = true,
showBackTrackButton = false,
showNextTrackButton = false,
controllerShowTimeMilliSeconds = 0,
controllerAutoShow = false,
showFullScreenButton = false,
),
usePlayerController = false,
enablePip = false,
enablePipWhenBackPressed = false,
volume = if (videoState == VideoState.Muted) 0f else 1f,
repeatMode = RepeatMode.ALL,
handleLifecycle = true,
autoPlay = true,
)
} else {
Box(modifier = Modifier.fillMaxSize())
}