diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index 30c5da369..467c9564b 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -315,6 +315,12 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { BackgroundHelper.stopBackgroundPlay(requireContext()) } + playerBinding.repeatBTN.setOnClickListener { + // Restart video if finished + exoPlayer.seekTo(0) + exoPlayer.play() + } + binding.playImageView.setOnClickListener { if (!exoPlayer.isPlaying) { // start or go on playing @@ -819,14 +825,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { if (isPlaying) { // Stop [BackgroundMode] service if it is running. BackgroundHelper.stopBackgroundPlay(requireContext()) - // video is playing - binding.playImageView.setImageResource(R.drawable.ic_pause) - } else if (exoPlayer.playbackState == Player.STATE_ENDED) { - // video has finished - binding.playImageView.setImageResource(R.drawable.ic_restart) - } else { - // player in any other state - binding.playImageView.setImageResource(R.drawable.ic_play) } if (isPlaying && PlayerHelper.sponsorBlockEnabled) { @@ -837,6 +835,18 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { } } + override fun onEvents(player: Player, events: Player.Events) { + super.onEvents(player, events) + if (events.containsAny( + Player.EVENT_PLAYBACK_STATE_CHANGED, + Player.EVENT_IS_PLAYING_CHANGED, + Player.EVENT_PLAY_WHEN_READY_CHANGED + ) + ) { + updatePlayPauseButton() + } + } + override fun onPlaybackStateChanged(playbackState: Int) { exoPlayerView.keepScreenOn = !( playbackState == Player.STATE_IDLE || @@ -963,6 +973,25 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { } } + private fun updatePlayPauseButton() { + if (exoPlayer.isPlaying) { + // video is playing + binding.playImageView.setImageResource(R.drawable.ic_pause) + playerBinding.exoPlayPause.visibility = View.VISIBLE + playerBinding.repeatBTN.visibility = View.GONE + } else if (exoPlayer.playbackState == Player.STATE_ENDED) { + // video has finished + binding.playImageView.setImageResource(R.drawable.ic_restart) + playerBinding.exoPlayPause.visibility = View.GONE + playerBinding.repeatBTN.visibility = View.VISIBLE + } else { + // player in any other state + binding.playImageView.setImageResource(R.drawable.ic_play) + playerBinding.exoPlayPause.visibility = View.VISIBLE + playerBinding.repeatBTN.visibility = View.GONE + } + } + private fun initializeRelatedVideos(relatedStreams: List?) { if (!PlayerHelper.relatedStreamsEnabled) return diff --git a/app/src/main/res/layout/exo_styled_player_control_view.xml b/app/src/main/res/layout/exo_styled_player_control_view.xml index f377d1a24..9a14b0a1c 100644 --- a/app/src/main/res/layout/exo_styled_player_control_view.xml +++ b/app/src/main/res/layout/exo_styled_player_control_view.xml @@ -283,6 +283,14 @@ android:background="?android:selectableItemBackgroundBorderless" app:tint="@android:color/white" /> + +