Merge pull request #6032 from Bnyro/master

fix: repeat current doesn't work if autoplay disabled
This commit is contained in:
Bnyro 2024-05-14 21:18:11 +02:00 committed by GitHub
commit 8f7fd2f05a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 18 deletions

View File

@ -45,7 +45,6 @@ import com.github.libretube.extensions.seekBy
import com.github.libretube.extensions.togglePlayPauseState import com.github.libretube.extensions.togglePlayPauseState
import com.github.libretube.extensions.updateParameters import com.github.libretube.extensions.updateParameters
import com.github.libretube.obj.VideoStats import com.github.libretube.obj.VideoStats
import com.github.libretube.util.PlayingQueue
import com.github.libretube.util.TextUtils import com.github.libretube.util.TextUtils
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -357,18 +356,9 @@ object PlayerHelper {
true true
) )
fun shouldPlayNextVideo(isPlaylist: Boolean = false): Boolean { fun isAutoPlayEnabled(isPlaylist: Boolean = false): Boolean {
// if there is no next video, it obviously should not be played return autoPlayEnabled || (isPlaylist && PreferenceHelper
if (!PlayingQueue.hasNext()) { .getBoolean(PreferenceKeys.AUTOPLAY_PLAYLISTS, false))
return false
}
return autoPlayEnabled || (
isPlaylist && PreferenceHelper.getBoolean(
PreferenceKeys.AUTOPLAY_PLAYLISTS,
false
)
)
} }
private val handleAudioFocus private val handleAudioFocus

View File

@ -131,7 +131,7 @@ class OnlinePlayerService : LifecycleService() {
when (state) { when (state) {
Player.STATE_ENDED -> { Player.STATE_ENDED -> {
if (PlayerHelper.shouldPlayNextVideo(playlistId != null) && !isTransitioning) playNextVideo() if (!isTransitioning) playNextVideo()
} }
Player.STATE_IDLE -> { Player.STATE_IDLE -> {
@ -353,6 +353,10 @@ class OnlinePlayerService : LifecycleService() {
return return
} }
saveWatchPosition()
if (!PlayerHelper.isAutoPlayEnabled(playlistId != null)) return
val nextVideo = nextId ?: PlayingQueue.getNext() ?: return val nextVideo = nextId ?: PlayingQueue.getNext() ?: return
// play new video on background // play new video on background

View File

@ -294,7 +294,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
// check if video has ended, next video is available and autoplay is enabled/the video is part of a played playlist. // check if video has ended, next video is available and autoplay is enabled/the video is part of a played playlist.
if (playbackState == Player.STATE_ENDED) { if (playbackState == Player.STATE_ENDED) {
if (!isTransitioning && PlayerHelper.shouldPlayNextVideo(playlistId != null)) { if (!isTransitioning) {
isTransitioning = true isTransitioning = true
if (PlayerHelper.autoPlayCountdown) { if (PlayerHelper.autoPlayCountdown) {
showAutoPlayCountdown() showAutoPlayCountdown()
@ -995,13 +995,13 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
return return
} }
if (!PlayerHelper.isAutoPlayEnabled(playlistId != null)) return
// save the current watch position before starting the next video // save the current watch position before starting the next video
saveWatchPosition() saveWatchPosition()
val nextVideoId = nextId ?: PlayingQueue.getNext() ?: return videoId = nextId ?: PlayingQueue.getNext() ?: return
isTransitioning = true isTransitioning = true
videoId = nextVideoId
// fix: if the fragment is recreated, play the current video, and not the initial one // fix: if the fragment is recreated, play the current video, and not the initial one
arguments?.run { arguments?.run {