mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 15:30:31 +05:30
Merge pull request #2828 from Bnyro/master
Keep the screen on while playing in the offline player
This commit is contained in:
commit
4a9a859c95
@ -167,7 +167,7 @@ class MainActivity : BaseActivity() {
|
||||
}
|
||||
R.id.searchResultFragment -> {
|
||||
navController.popBackStack(R.id.searchFragment, true) ||
|
||||
navController.popBackStack()
|
||||
navController.popBackStack()
|
||||
}
|
||||
else -> {
|
||||
navController.popBackStack()
|
||||
|
@ -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>?) {
|
||||
|
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user