From c5ae059399eab9bf3ffc5243706bd69ea6f8a513 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Fri, 1 Nov 2024 23:48:27 +0100 Subject: [PATCH] make aspect ratio of pip view update when the content aspect ratio changes --- .../newplayer/ui/videoplayer/VideoPlayerUI.kt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/VideoPlayerUI.kt b/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/VideoPlayerUI.kt index 41dd3bd..0270d8c 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/VideoPlayerUI.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/VideoPlayerUI.kt @@ -57,6 +57,7 @@ import net.newpipe.newplayer.ui.selection_ui.ChapterSelectUI import net.newpipe.newplayer.ui.videoplayer.pip.getPipParams import net.newpipe.newplayer.ui.videoplayer.pip.supportsPip import net.newpipe.newplayer.ui.common.getEmbeddedUiConfig +import net.newpipe.newplayer.uiModel.UIModeState @OptIn(UnstableApi::class) @Composable @@ -93,6 +94,19 @@ internal fun VideoPlayerUi(viewModel: InternalNewPlayerViewModel, uiState: NewPl } } + // this is there to update the aspect ratio of the pip window the aspect ratio of the + // content changes. + LaunchedEffect(uiState.contentRatio) { + if (uiState.uiMode == UIModeState.PIP + && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O + && supportsPip(activity) + ) { + val pipParams = getPipParams(uiState.contentRatio, videoViewBounds) + if(pipParams != null) + activity.setPictureInPictureParams(pipParams) + } + } + Surface( modifier = Modifier .then( @@ -128,7 +142,7 @@ internal fun VideoPlayerUi(viewModel: InternalNewPlayerViewModel, uiState: NewPl // Disable this animation as it induces ghost tabs //AnimatedVisibility(visible = uiState.uiMode.isStreamSelect) { - if(uiState.uiMode.isStreamSelect) { + if (uiState.uiMode.isStreamSelect) { Surface( modifier = Modifier.fillMaxSize(), color = STREAMSELECT_UI_BACKGROUND_COLOR @@ -143,7 +157,7 @@ internal fun VideoPlayerUi(viewModel: InternalNewPlayerViewModel, uiState: NewPl // Disable this animation as it induces ghost tabs //AnimatedVisibility(visible = uiState.uiMode.isChapterSelect) { - if(uiState.uiMode.isChapterSelect) { + if (uiState.uiMode.isChapterSelect) { Surface( modifier = Modifier.fillMaxSize(), color = STREAMSELECT_UI_BACKGROUND_COLOR