Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make PlayerView remember its fullscreen button state? #184

Closed
DassieKlip opened this issue Oct 11, 2022 · 2 comments
Closed

How to make PlayerView remember its fullscreen button state? #184

DassieKlip opened this issue Oct 11, 2022 · 2 comments
Assignees

Comments

@DassieKlip
Copy link

Good day,

I am using ExoPlayer and PlayerView with Jetpack Compose.

Dependencies:
androidx.media3:media3-exoplayer:1.0.0-beta02
androidx.media3:media3-ui:1.0.0-beta02

The ExoPlayer instance is kept in the view model.

If the user enters fullscreen mode, and then changes the device orientation, then the view is recomposed, and the PlayerView recreated with the fullscreen button state defaulting to 'false'.

Consequently, the user has to tap the fullscreen button twice to exit fullscreen mode.

There isn't an exposed property to set the fullscreen state, so is there a way to have PlayerView created with the fullscreen state of 'true' or have it remember that is was 'true'?

Is this an oversight? Or am I using PlayerView incorrectly?

I do not think that the fullscreen button should force a particular orientation change, because the video could have been recorded in landscape mode or portrait mode.

import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.viewinterop.AndroidView
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.ui.AspectRatioFrameLayout
import androidx.media3.ui.PlayerView

private const val KEY = "VIDEO_VIEWER_KEY"

@Composable
fun VideoViewer(
    exoPlayer: ExoPlayer,
    onFullscreenToggle: (Boolean) -> Unit
) {
    AndroidView(factory = { context ->
        PlayerView(context).apply {
            setFullscreenButtonClickListener { isFullscreen -> onFullscreenToggle(isFullscreen) }

            showController()

            useController = true
            resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT

            player = exoPlayer

            layoutParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
        }
    })

    DisposableEffect(key1 = KEY) {
        onDispose {
            exoPlayer.pause()
            exoPlayer.seekToDefaultPosition()
            exoPlayer.clearMediaItems()
        }
    }
}
@icbaker
Copy link
Collaborator

icbaker commented Oct 24, 2022

I think this basically boils down to a duplicate of google/ExoPlayer#10391 (note: StyledPlayerView in ExoPlayer is spelt PlayerView in media3: #186 (comment)).

@icbaker icbaker closed this as completed Oct 24, 2022
@androidx androidx locked and limited conversation to collaborators Mar 3, 2023
@oceanjules
Copy link
Contributor

Will be fixed by #1653

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants