mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
feat: allow resuming playback after disconnect
This commit is contained in:
parent
087a39757f
commit
1d236ded79
19
app/src/main/java/com/github/libretube/extensions/Player.kt
Normal file
19
app/src/main/java/com/github/libretube/extensions/Player.kt
Normal file
@ -0,0 +1,19 @@
|
||||
package com.github.libretube.extensions
|
||||
|
||||
import androidx.media3.common.Player
|
||||
|
||||
fun Player.togglePlayPauseState() {
|
||||
when {
|
||||
playerError != null -> {
|
||||
prepare()
|
||||
play()
|
||||
}
|
||||
|
||||
!isPlaying && playbackState == Player.STATE_ENDED -> {
|
||||
seekTo(0)
|
||||
}
|
||||
|
||||
!isPlaying && !isLoading -> play()
|
||||
else -> pause()
|
||||
}
|
||||
}
|
@ -79,6 +79,7 @@ import com.github.libretube.extensions.serializableExtra
|
||||
import com.github.libretube.extensions.setMetadata
|
||||
import com.github.libretube.extensions.toID
|
||||
import com.github.libretube.extensions.toastFromMainDispatcher
|
||||
import com.github.libretube.extensions.togglePlayPauseState
|
||||
import com.github.libretube.extensions.updateParameters
|
||||
import com.github.libretube.helpers.BackgroundHelper
|
||||
import com.github.libretube.helpers.ImageHelper
|
||||
@ -391,14 +392,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
playerBinding.autoPlay.isVisible = true
|
||||
|
||||
binding.playImageView.setOnClickListener {
|
||||
when {
|
||||
!exoPlayer.isPlaying && exoPlayer.playbackState == Player.STATE_ENDED -> {
|
||||
exoPlayer.seekTo(0)
|
||||
}
|
||||
|
||||
!exoPlayer.isPlaying -> exoPlayer.play()
|
||||
else -> exoPlayer.pause()
|
||||
}
|
||||
exoPlayer.togglePlayPauseState()
|
||||
}
|
||||
|
||||
// video description and chapters toggle
|
||||
|
@ -41,6 +41,7 @@ import com.github.libretube.extensions.dpToPx
|
||||
import com.github.libretube.extensions.normalize
|
||||
import com.github.libretube.extensions.round
|
||||
import com.github.libretube.extensions.seekBy
|
||||
import com.github.libretube.extensions.togglePlayPauseState
|
||||
import com.github.libretube.helpers.AudioHelper
|
||||
import com.github.libretube.helpers.BrightnessHelper
|
||||
import com.github.libretube.helpers.PlayerHelper
|
||||
@ -156,14 +157,7 @@ open class CustomExoPlayerView(
|
||||
}
|
||||
|
||||
binding.playPauseBTN.setOnClickListener {
|
||||
when {
|
||||
player?.isPlaying == false && player?.playbackState == Player.STATE_ENDED -> {
|
||||
player?.seekTo(0)
|
||||
}
|
||||
|
||||
player?.isPlaying == false && player?.isLoading == false -> player?.play()
|
||||
else -> player?.pause()
|
||||
}
|
||||
player?.togglePlayPauseState()
|
||||
}
|
||||
|
||||
player?.addListener(object : Player.Listener {
|
||||
|
@ -299,6 +299,7 @@ class NowPlayingNotification(
|
||||
}
|
||||
|
||||
PLAY_PAUSE -> {
|
||||
if (player.playerError != null) player.prepare()
|
||||
if (player.isPlaying) player.pause() else player.play()
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user