compose-video icon indicating copy to clipboard operation
compose-video copied to clipboard

Question regarding lifecycle

Open rtammekivi opened this issue 2 years ago • 3 comments
trafficstars

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.

rtammekivi avatar Oct 05 '23 20:10 rtammekivi

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!

dsa28s avatar Oct 19 '23 03:10 dsa28s

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,
)

AradiPatrik avatar Dec 12 '23 04:12 AradiPatrik

@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())
}

AradiPatrik avatar Dec 12 '23 04:12 AradiPatrik