From 9f5814e4196bf599d4d6f18cbe5e2f0aee97cb36 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Thu, 2 Jun 2022 22:54:18 +0200 Subject: [PATCH] . --- .../libretube/fragments/PlayerFragment.kt | 79 ++++++++++--------- 1 file changed, 40 insertions(+), 39 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 d5c1a82bc..44d701271 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -451,6 +451,46 @@ class PlayerFragment : Fragment() { view.findViewById(R.id.player_title).text = response.title view.findViewById(R.id.player_description).text = response.description + // Listener for play and pause icon change + exoPlayer.addListener(object : com.google.android.exoplayer2.Player.Listener { + override fun onIsPlayingChanged(isPlaying: Boolean) { + if (isPlaying && SponsorBlockSettings.sponsorBlockEnabled) { + exoPlayerView.postDelayed( + this@PlayerFragment::checkForSegments, + 100 + ) + } + } + + override fun onPlayerStateChanged( + playWhenReady: Boolean, + playbackState: Int + ) { + + exoPlayerView.keepScreenOn = !( + playbackState == Player.STATE_IDLE || + playbackState == Player.STATE_ENDED || + !playWhenReady + ) + + if (playWhenReady && playbackState == Player.STATE_READY) { + // media actually playing + view.findViewById(R.id.play_imageView) + .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) + view.findViewById(R.id.play_imageView) + .setImageResource(R.drawable.ic_play) + } else { + // player paused in any state + view.findViewById(R.id.play_imageView) + .setImageResource(R.drawable.ic_play) + } + } + }) + // share button view.findViewById(R.id.relPlayer_share).setOnClickListener { showShareDialog(requireContext(), videoId!!) @@ -513,45 +553,6 @@ class PlayerFragment : Fragment() { description } - // Listener for play and pause icon change - exoPlayer.addListener(object : com.google.android.exoplayer2.Player.Listener { - override fun onIsPlayingChanged(isPlaying: Boolean) { - if (isPlaying && SponsorBlockSettings.sponsorBlockEnabled) { - exoPlayerView.postDelayed( - this@PlayerFragment::checkForSegments, - 100 - ) - } - } - - override fun onPlayerStateChanged( - playWhenReady: Boolean, - playbackState: Int - ) { - - exoPlayerView.keepScreenOn = !( - playbackState == Player.STATE_IDLE || - playbackState == Player.STATE_ENDED || - !playWhenReady - ) - - if (playWhenReady && playbackState == Player.STATE_READY) { - // media actually playing - view.findViewById(R.id.play_imageView) - .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) - view.findViewById(R.id.play_imageView) - .setImageResource(R.drawable.ic_play) - } else { - // player paused in any state - view.findViewById(R.id.play_imageView) - .setImageResource(R.drawable.ic_play) - } - } - }) view.findViewById(R.id.player_channel).setOnClickListener { val activity = view.context as MainActivity