Merge pull request #2828 from Bnyro/master

Keep the screen on while playing in the offline player
This commit is contained in:
Bnyro 2023-01-22 19:36:17 +01:00 committed by GitHub
commit 4a9a859c95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 34 deletions

View File

@ -919,11 +919,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
}
override fun onPlaybackStateChanged(playbackState: Int) {
exoPlayerView.keepScreenOn = !(
playbackState == Player.STATE_IDLE ||
playbackState == Player.STATE_ENDED
)
// save the watch position to the database
// only called when the position is unequal to 0, otherwise it would become reset
// before the player can seek to the saved position from videos of the queue
@ -1120,16 +1115,13 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
}
private fun updatePlayPauseButton() {
if (exoPlayer.isPlaying) {
// 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)
binding.playImageView.setImageResource(
when {
exoPlayer.isPlaying -> R.drawable.ic_pause
exoPlayer.playbackState == Player.STATE_ENDED -> R.drawable.ic_restart
else -> R.drawable.ic_play
}
)
}
private fun initializeRelatedVideos(relatedStreams: List<StreamItem>?) {

View File

@ -152,16 +152,12 @@ internal class CustomExoPlayerView(
}
binding.playPauseBTN.setOnClickListener {
if (player?.isPlaying == false) {
// start or go on playing
if (player?.playbackState == Player.STATE_ENDED) {
// restart video if finished
when {
player?.isPlaying == false && player?.playbackState == Player.STATE_ENDED -> {
player?.seekTo(0)
}
player?.play()
} else {
// pause the video
player?.pause()
player?.isPlaying == false -> player?.play()
else -> player?.pause()
}
}
@ -177,6 +173,15 @@ internal class CustomExoPlayerView(
updatePlayPauseButton()
}
}
override fun onPlaybackStateChanged(playbackState: Int) {
// keep the screen on if the video is not ended or paused
keepScreenOn = !(
listOf(Player.STATE_IDLE, Player.STATE_ENDED)
.contains(playbackState)
)
super.onPlaybackStateChanged(playbackState)
}
})
playerViewModel?.isFullscreen?.observe(viewLifecycleOwner!!) { isFullscreen ->
@ -189,16 +194,13 @@ internal class CustomExoPlayerView(
}
private fun updatePlayPauseButton() {
if (player?.isPlaying == true) {
// video is playing
binding.playPauseBTN.setImageResource(R.drawable.ic_pause)
} else if (player?.playbackState == Player.STATE_ENDED) {
// video has finished
binding.playPauseBTN.setImageResource(R.drawable.ic_restart)
} else {
// player in any other state
binding.playPauseBTN.setImageResource(R.drawable.ic_play)
binding.playPauseBTN.setImageResource(
when {
player?.isPlaying == true -> R.drawable.ic_pause
player?.playbackState == Player.STATE_ENDED -> R.drawable.ic_restart
else -> R.drawable.ic_play
}
)
}
private fun cancelHideControllerTask() {