mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
Merge pull request #2171 from Kruna1Pate1/fix/minimized-player
Fix minimized player and repeat button
This commit is contained in:
commit
085eff2041
@ -315,10 +315,9 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
BackgroundHelper.stopBackgroundPlay(requireContext())
|
BackgroundHelper.stopBackgroundPlay(requireContext())
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.playImageView.setOnClickListener {
|
val playPauseClickListner = View.OnClickListener {
|
||||||
if (!exoPlayer.isPlaying) {
|
if (!exoPlayer.isPlaying) {
|
||||||
// start or go on playing
|
// start or go on playing
|
||||||
binding.playImageView.setImageResource(R.drawable.ic_pause)
|
|
||||||
if (exoPlayer.playbackState == Player.STATE_ENDED) {
|
if (exoPlayer.playbackState == Player.STATE_ENDED) {
|
||||||
// restart video if finished
|
// restart video if finished
|
||||||
exoPlayer.seekTo(0)
|
exoPlayer.seekTo(0)
|
||||||
@ -326,10 +325,11 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
exoPlayer.play()
|
exoPlayer.play()
|
||||||
} else {
|
} else {
|
||||||
// pause the video
|
// pause the video
|
||||||
binding.playImageView.setImageResource(R.drawable.ic_play)
|
|
||||||
exoPlayer.pause()
|
exoPlayer.pause()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
playerBinding.playPauseBTN.setOnClickListener(playPauseClickListner)
|
||||||
|
binding.playImageView.setOnClickListener(playPauseClickListner)
|
||||||
|
|
||||||
// video description and chapters toggle
|
// video description and chapters toggle
|
||||||
binding.playerTitleLayout.setOnClickListener {
|
binding.playerTitleLayout.setOnClickListener {
|
||||||
@ -829,6 +829,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) {
|
override fun onPlaybackStateChanged(playbackState: Int) {
|
||||||
exoPlayerView.keepScreenOn = !(
|
exoPlayerView.keepScreenOn = !(
|
||||||
playbackState == Player.STATE_IDLE ||
|
playbackState == Player.STATE_IDLE ||
|
||||||
@ -847,22 +859,11 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
playNextVideo()
|
playNextVideo()
|
||||||
}
|
}
|
||||||
|
|
||||||
when (playbackState) {
|
if (playbackState == Player.STATE_READY) {
|
||||||
Player.STATE_READY -> {
|
// media actually playing
|
||||||
// media actually playing
|
transitioning = false
|
||||||
transitioning = false
|
// update the PiP params to use the correct aspect ratio
|
||||||
binding.playImageView.setImageResource(R.drawable.ic_pause)
|
if (usePiP()) activity?.setPictureInPictureParams(getPipParams())
|
||||||
// update the PiP params to use the correct aspect ratio
|
|
||||||
if (usePiP()) activity?.setPictureInPictureParams(getPipParams())
|
|
||||||
}
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// save the watch position when paused
|
// save the watch position when paused
|
||||||
@ -966,6 +967,22 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updatePlayPauseButton() {
|
||||||
|
if (exoPlayer.isPlaying) {
|
||||||
|
// video is playing
|
||||||
|
binding.playImageView.setImageResource(R.drawable.ic_pause)
|
||||||
|
playerBinding.playPauseBTN.setImageResource(R.drawable.ic_pause)
|
||||||
|
} else if (exoPlayer.playbackState == Player.STATE_ENDED) {
|
||||||
|
// video has finished
|
||||||
|
binding.playImageView.setImageResource(R.drawable.ic_restart)
|
||||||
|
playerBinding.playPauseBTN.setImageResource(R.drawable.ic_restart)
|
||||||
|
} else {
|
||||||
|
// player in any other state
|
||||||
|
binding.playImageView.setImageResource(R.drawable.ic_play)
|
||||||
|
playerBinding.playPauseBTN.setImageResource(R.drawable.ic_play)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun initializeRelatedVideos(relatedStreams: List<StreamItem>?) {
|
private fun initializeRelatedVideos(relatedStreams: List<StreamItem>?) {
|
||||||
if (!PlayerHelper.relatedStreamsEnabled) return
|
if (!PlayerHelper.relatedStreamsEnabled) return
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ internal class CustomExoPlayerView(
|
|||||||
binding.exoBottomBar.visibility = visibility
|
binding.exoBottomBar.visibility = visibility
|
||||||
binding.closeImageButton.visibility = visibility
|
binding.closeImageButton.visibility = visibility
|
||||||
binding.exoTitle.visibility = visibility
|
binding.exoTitle.visibility = visibility
|
||||||
binding.exoPlayPause.visibility = visibility
|
binding.playPauseBTN.visibility = visibility
|
||||||
|
|
||||||
// disable tap and swipe gesture if the player is locked
|
// disable tap and swipe gesture if the player is locked
|
||||||
playerGestureController.isEnabled = isLocked
|
playerGestureController.isEnabled = isLocked
|
||||||
|
@ -277,7 +277,7 @@
|
|||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@id/exo_play_pause"
|
android:id="@+id/playPauseBTN"
|
||||||
style="@style/ExoStyledControls.Button.Center.PlayPause"
|
style="@style/ExoStyledControls.Button.Center.PlayPause"
|
||||||
android:layout_marginHorizontal="10dp"
|
android:layout_marginHorizontal="10dp"
|
||||||
android:background="?android:selectableItemBackgroundBorderless"
|
android:background="?android:selectableItemBackgroundBorderless"
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?><!-- Replaces the drawables of the default exoplayer controls (see https://github.com/google/ExoPlayer/blob/release-v2/library/ui/src/main/res/values/drawables.xml) -->
|
<?xml version="1.0" encoding="utf-8"?><!-- Replaces the drawables of the default exoplayer controls (see https://github.com/google/ExoPlayer/blob/release-v2/library/ui/src/main/res/values/drawables.xml) -->
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<drawable name="exo_styled_controls_play">@drawable/ic_play</drawable>
|
|
||||||
<drawable name="exo_styled_controls_pause">@drawable/ic_pause</drawable>
|
|
||||||
<drawable name="exo_notification_small_icon">@drawable/ic_launcher_lockscreen</drawable>
|
<drawable name="exo_notification_small_icon">@drawable/ic_launcher_lockscreen</drawable>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
Loading…
x
Reference in New Issue
Block a user