From b997d0c6d0591e97faadd1c78515823eba13961e Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 27 Aug 2022 11:42:17 +0200 Subject: [PATCH 1/3] close pip by stopping notification --- .../java/com/github/libretube/fragments/PlayerFragment.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index 5b867d9e2..52ed71330 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -1136,6 +1136,14 @@ class PlayerFragment : BaseFragment() { // player paused in any state binding.playImageView.setImageResource(R.drawable.ic_play) } + + if (SDK_INT >= Build.VERSION_CODES.O) { + // listen for the stop button in the notification + if (playbackState == PlaybackState.STATE_STOPPED) { + // finish PiP by finishing the activity + activity?.finish() + } + } } }) From 93315aeb63501f9436d022a89ec4cbea7aa85d7c Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 27 Aug 2022 11:44:43 +0200 Subject: [PATCH 2/3] only do in PiP --- .../main/java/com/github/libretube/fragments/PlayerFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index 52ed71330..1fa9c1652 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -1137,7 +1137,7 @@ class PlayerFragment : BaseFragment() { binding.playImageView.setImageResource(R.drawable.ic_play) } - if (SDK_INT >= Build.VERSION_CODES.O) { + if (SDK_INT >= Build.VERSION_CODES.O && activity?.isInPictureInPictureMode!!) { // listen for the stop button in the notification if (playbackState == PlaybackState.STATE_STOPPED) { // finish PiP by finishing the activity From c7ed00908cefddc5e65a861f877405444777f680 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 27 Aug 2022 11:55:29 +0200 Subject: [PATCH 3/3] fix deprecation --- .../libretube/fragments/PlayerFragment.kt | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index 1fa9c1652..d277719ca 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -1100,18 +1100,14 @@ class PlayerFragment : BaseFragment() { } } - @Deprecated(message = "Deprecated", level = DeprecationLevel.HIDDEN) - override fun onPlayerStateChanged( - playWhenReady: Boolean, - playbackState: Int - ) { + override fun onPlaybackStateChanged(playbackState: Int) { exoPlayerView.keepScreenOn = !( playbackState == Player.STATE_IDLE || - playbackState == Player.STATE_ENDED || - !playWhenReady + playbackState == Player.STATE_ENDED ) // check if video has ended, next video is available and autoplay is enabled. + @Suppress("DEPRECATION") if ( playbackState == Player.STATE_ENDED && nextStreamId != null && @@ -1123,27 +1119,21 @@ class PlayerFragment : BaseFragment() { if (autoplayEnabled) playNextVideo() } - if (playWhenReady && playbackState == Player.STATE_READY) { + if (playbackState == Player.STATE_READY) { // media actually playing transitioning = false binding.playImageView.setImageResource(R.drawable.ic_pause) - } else if (playWhenReady) { - // might be idle (plays after prepare()), - // buffering (plays when data available) - // or ended (plays when seek away from end) - binding.playImageView.setImageResource(R.drawable.ic_play) } else { // player paused in any state binding.playImageView.setImageResource(R.drawable.ic_play) } - if (SDK_INT >= Build.VERSION_CODES.O && activity?.isInPictureInPictureMode!!) { - // listen for the stop button in the notification - if (playbackState == PlaybackState.STATE_STOPPED) { - // finish PiP by finishing the activity - activity?.finish() - } + // listen for the stop button in the notification + if (playbackState == PlaybackState.STATE_STOPPED) { + // finish PiP by finishing the activity + activity?.finish() } + super.onPlaybackStateChanged(playbackState) } }) @@ -1199,6 +1189,7 @@ class PlayerFragment : BaseFragment() { Html.fromHtml(description, Html.FROM_HTML_MODE_COMPACT) .trim() } else { + @Suppress("DEPRECATION") Html.fromHtml(description).trim() } } else {