mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
Fix player control repeat icon on the video end
A new image button for reapeat button is needed, changing `exo_play_pause` doesn't work because it is updated by `StyledPlayerControlView`. So, when the video ends hide `exo_play_pause` and show `repeatBTN`.
This commit is contained in:
parent
d3d75d8bc8
commit
9dd505917d
@ -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<StreamItem>?) {
|
||||
if (!PlayerHelper.relatedStreamsEnabled) return
|
||||
|
||||
|
@ -283,6 +283,14 @@
|
||||
android:background="?android:selectableItemBackgroundBorderless"
|
||||
app:tint="@android:color/white" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/repeatBTN"
|
||||
style="@style/ExoStyledControls.Button.Center.PlayPause"
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:background="?android:selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/ic_restart"
|
||||
app:tint="@android:color/white" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/forwardBTN"
|
||||
android:layout_width="wrap_content"
|
||||
|
Loading…
Reference in New Issue
Block a user