From 42df641c03e8522feeb77b4bde11799705a074e0 Mon Sep 17 00:00:00 2001 From: Natanel Shitrit <65548905+Natanel-Shitrit@users.noreply.github.com> Date: Sat, 3 Feb 2024 23:04:48 +0200 Subject: [PATCH] feat: automatic PiP animation (#648) * Add automatic PiP animation * Fix linting * Fix linting * chore: fix merge conflict * fix: disable pip gesture when media is paused * fix: crash when gestures are disabled * fix: keep auto enter enabled after using button --------- Co-authored-by: Cd16d <98320806+cd16b@users.noreply.github.com> Co-authored-by: Jarne Demeulemeester --- .../dev/jdtech/jellyfin/PlayerActivity.kt | 70 ++++++++++++------- .../viewmodels/PlayerActivityViewModel.kt | 8 ++- 2 files changed, 51 insertions(+), 27 deletions(-) diff --git a/app/phone/src/main/java/dev/jdtech/jellyfin/PlayerActivity.kt b/app/phone/src/main/java/dev/jdtech/jellyfin/PlayerActivity.kt index 33c8d15a..5171533a 100644 --- a/app/phone/src/main/java/dev/jdtech/jellyfin/PlayerActivity.kt +++ b/app/phone/src/main/java/dev/jdtech/jellyfin/PlayerActivity.kt @@ -169,6 +169,11 @@ class PlayerActivity : BasePlayerActivity() { viewModel.eventsChannelFlow.collect { event -> when (event) { is PlayerEvents.NavigateBack -> finish() + is PlayerEvents.IsPlayingChanged -> { + if (appPreferences.playerPipGesture) { + setPictureInPictureParams(pipParams(event.isPlaying)) + } + } } } } @@ -263,12 +268,16 @@ class PlayerActivity : BasePlayerActivity() { } override fun onUserLeaveHint() { - if (appPreferences.playerPipGesture && viewModel.player.isPlaying && !isControlsLocked) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S && + appPreferences.playerPipGesture && + viewModel.player.isPlaying && + !isControlsLocked + ) { pictureInPicture() } } - private fun pipParams(): PictureInPictureParams { + private fun pipParams(enableAutoEnter: Boolean = viewModel.player.isPlaying): PictureInPictureParams { val displayAspectRatio = Rational(binding.playerView.width, binding.playerView.height) val aspectRatio = binding.playerView.player?.videoSize?.let { @@ -296,26 +305,21 @@ class PlayerActivity : BasePlayerActivity() { ) } - return PictureInPictureParams.Builder() + val builder = PictureInPictureParams.Builder() .setAspectRatio(aspectRatio) .setSourceRectHint(sourceRectHint) - .build() + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + builder.setAutoEnterEnabled(enableAutoEnter) + } + + return builder.build() } private fun pictureInPicture() { if (!isPipSupported) { return } - binding.playerView.useController = false - binding.playerView.findViewById