mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +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 -> {
|
R.id.searchResultFragment -> {
|
||||||
navController.popBackStack(R.id.searchFragment, true) ||
|
navController.popBackStack(R.id.searchFragment, true) ||
|
||||||
navController.popBackStack()
|
navController.popBackStack()
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
navController.popBackStack()
|
navController.popBackStack()
|
||||||
|
@ -919,11 +919,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onPlaybackStateChanged(playbackState: Int) {
|
override fun onPlaybackStateChanged(playbackState: Int) {
|
||||||
exoPlayerView.keepScreenOn = !(
|
|
||||||
playbackState == Player.STATE_IDLE ||
|
|
||||||
playbackState == Player.STATE_ENDED
|
|
||||||
)
|
|
||||||
|
|
||||||
// save the watch position to the database
|
// save the watch position to the database
|
||||||
// only called when the position is unequal to 0, otherwise it would become reset
|
// 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
|
// 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() {
|
private fun updatePlayPauseButton() {
|
||||||
if (exoPlayer.isPlaying) {
|
binding.playImageView.setImageResource(
|
||||||
// video is playing
|
when {
|
||||||
binding.playImageView.setImageResource(R.drawable.ic_pause)
|
exoPlayer.isPlaying -> R.drawable.ic_pause
|
||||||
} else if (exoPlayer.playbackState == Player.STATE_ENDED) {
|
exoPlayer.playbackState == Player.STATE_ENDED -> R.drawable.ic_restart
|
||||||
// video has finished
|
else -> R.drawable.ic_play
|
||||||
binding.playImageView.setImageResource(R.drawable.ic_restart)
|
}
|
||||||
} else {
|
)
|
||||||
// player in any other state
|
|
||||||
binding.playImageView.setImageResource(R.drawable.ic_play)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initializeRelatedVideos(relatedStreams: List<StreamItem>?) {
|
private fun initializeRelatedVideos(relatedStreams: List<StreamItem>?) {
|
||||||
|
@ -152,16 +152,12 @@ internal class CustomExoPlayerView(
|
|||||||
}
|
}
|
||||||
|
|
||||||
binding.playPauseBTN.setOnClickListener {
|
binding.playPauseBTN.setOnClickListener {
|
||||||
if (player?.isPlaying == false) {
|
when {
|
||||||
// start or go on playing
|
player?.isPlaying == false && player?.playbackState == Player.STATE_ENDED -> {
|
||||||
if (player?.playbackState == Player.STATE_ENDED) {
|
|
||||||
// restart video if finished
|
|
||||||
player?.seekTo(0)
|
player?.seekTo(0)
|
||||||
}
|
}
|
||||||
player?.play()
|
player?.isPlaying == false -> player?.play()
|
||||||
} else {
|
else -> player?.pause()
|
||||||
// pause the video
|
|
||||||
player?.pause()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,6 +173,15 @@ internal class CustomExoPlayerView(
|
|||||||
updatePlayPauseButton()
|
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 ->
|
playerViewModel?.isFullscreen?.observe(viewLifecycleOwner!!) { isFullscreen ->
|
||||||
@ -189,16 +194,13 @@ internal class CustomExoPlayerView(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updatePlayPauseButton() {
|
private fun updatePlayPauseButton() {
|
||||||
if (player?.isPlaying == true) {
|
binding.playPauseBTN.setImageResource(
|
||||||
// video is playing
|
when {
|
||||||
binding.playPauseBTN.setImageResource(R.drawable.ic_pause)
|
player?.isPlaying == true -> R.drawable.ic_pause
|
||||||
} else if (player?.playbackState == Player.STATE_ENDED) {
|
player?.playbackState == Player.STATE_ENDED -> R.drawable.ic_restart
|
||||||
// video has finished
|
else -> R.drawable.ic_play
|
||||||
binding.playPauseBTN.setImageResource(R.drawable.ic_restart)
|
}
|
||||||
} else {
|
)
|
||||||
// player in any other state
|
|
||||||
binding.playPauseBTN.setImageResource(R.drawable.ic_play)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun cancelHideControllerTask() {
|
private fun cancelHideControllerTask() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user