Fix exo player not playing next up

This commit is contained in:
Damontecres 2025-11-08 13:35:20 -05:00
parent 5ff7c1ffa9
commit 32712c39a0
No known key found for this signature in database
2 changed files with 13 additions and 21 deletions

View file

@ -359,7 +359,7 @@ fun PlaybackPage(
PlaybackAction.Next -> { PlaybackAction.Next -> {
// TODO focus is lost // TODO focus is lost
viewModel.playUpNextUp() viewModel.playNextUp()
} }
PlaybackAction.Previous -> { PlaybackAction.Previous -> {
@ -452,14 +452,14 @@ fun PlaybackPage(
if (autoPlayEnabled) { if (autoPlayEnabled) {
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
if (timeLeft == 0L) { if (timeLeft == 0L) {
viewModel.playUpNextUp() viewModel.playNextUp()
} else { } else {
while (timeLeft > 0) { while (timeLeft > 0) {
delay(1.seconds) delay(1.seconds)
timeLeft-- timeLeft--
} }
if (timeLeft == 0L && autoPlayEnabled) { if (timeLeft == 0L && autoPlayEnabled) {
viewModel.playUpNextUp() viewModel.playNextUp()
} }
} }
} }
@ -475,7 +475,7 @@ fun PlaybackPage(
aspectRatio = it.data.primaryImageAspectRatio?.toFloat() ?: (16f / 9), aspectRatio = it.data.primaryImageAspectRatio?.toFloat() ?: (16f / 9),
onClick = { onClick = {
viewModel.reportInteraction() viewModel.reportInteraction()
viewModel.playUpNextUp() viewModel.playNextUp()
}, },
timeLeft = if (autoPlayEnabled) timeLeft.seconds else null, timeLeft = if (autoPlayEnabled) timeLeft.seconds else null,
modifier = modifier =

View file

@ -251,7 +251,7 @@ class PlaybackViewModel
destination.forceTranscoding, destination.forceTranscoding,
) )
if (!played) { if (!played) {
playUpNextUp() playNextUp()
} }
if (!isPlaylist && queriedItem.type == BaseItemKind.EPISODE) { if (!isPlaylist && queriedItem.type == BaseItemKind.EPISODE) {
@ -429,7 +429,7 @@ class PlaybackViewModel
val playerBackend = preferences.appPreferences.playbackPreferences.playerBackend val playerBackend = preferences.appPreferences.playbackPreferences.playerBackend
val currentPlayback = this@PlaybackViewModel.currentPlayback.value val currentPlayback = this@PlaybackViewModel.currentPlayback.value
if (currentPlayback != null && currentPlayback.playMethod == PlayMethod.DIRECT_PLAY) { if (currentPlayback != null && currentPlayback.itemId == item.id && currentPlayback.playMethod == PlayMethod.DIRECT_PLAY) {
// If direct playing, can try to switch tracks without playback restarting // If direct playing, can try to switch tracks without playback restarting
// Except for external subtitles // Except for external subtitles
// TODO there's probably no reason why we can't add external subtitles? // TODO there's probably no reason why we can't add external subtitles?
@ -483,21 +483,11 @@ class PlaybackViewModel
} }
} }
// TODO
// if (currentItemPlayback.let {
// it.itemId == itemId &&
// it.audioIndex == audioIndex &&
// it.subtitleIndex == subtitleIndex
// } == true
// ) {
// Timber.i("No change in playback for changeStreams")
// return@withContext
// }
Timber.d( Timber.d(
"changeStreams: userInitiated=$userInitiated, audioIndex=$audioIndex, subtitleIndex=$subtitleIndex, " + "changeStreams: userInitiated=$userInitiated, audioIndex=$audioIndex, subtitleIndex=$subtitleIndex, " +
"enableDirectPlay=$enableDirectPlay, enableDirectStream=$enableDirectStream", "enableDirectPlay=$enableDirectPlay, enableDirectStream=$enableDirectStream",
) )
// TODO if the new audio or subtitle index is already in the streams (eg direct play), should toggle in the player instead
val maxBitrate = val maxBitrate =
preferences.appPreferences.playbackPreferences.maxBitrate preferences.appPreferences.playbackPreferences.maxBitrate
.takeIf { it > 0 } ?: AppPreference.DEFAULT_BITRATE .takeIf { it > 0 } ?: AppPreference.DEFAULT_BITRATE
@ -595,6 +585,7 @@ class PlaybackViewModel
val playback = val playback =
CurrentPlayback( CurrentPlayback(
itemId = item.id,
backend = preferences.appPreferences.playbackPreferences.playerBackend, backend = preferences.appPreferences.playbackPreferences.playerBackend,
tracks = listOf(), tracks = listOf(),
playMethod = transcodeType, playMethod = transcodeType,
@ -831,7 +822,7 @@ class PlaybackViewModel
} }
} }
fun playUpNextUp() { fun playNextUp() {
playlist.value?.let { playlist.value?.let {
if (it.hasNext()) { if (it.hasNext()) {
viewModelScope.launchIO { viewModelScope.launchIO {
@ -839,7 +830,7 @@ class PlaybackViewModel
val item = it.getAndAdvance() val item = it.getAndAdvance()
val played = play(item.data, 0) val played = play(item.data, 0)
if (!played) { if (!played) {
playUpNextUp() playNextUp()
} }
} }
} }
@ -872,7 +863,7 @@ class PlaybackViewModel
if (toPlay != null) { if (toPlay != null) {
val played = play(toPlay.data, 0) val played = play(toPlay.data, 0)
if (!played) { if (!played) {
playUpNextUp() playNextUp()
} }
} else { } else {
// TODO // TODO
@ -941,7 +932,7 @@ class PlaybackViewModel
PlaystateCommand.PAUSE -> player.pause() PlaystateCommand.PAUSE -> player.pause()
PlaystateCommand.UNPAUSE -> player.play() PlaystateCommand.UNPAUSE -> player.play()
PlaystateCommand.NEXT_TRACK -> playUpNextUp() PlaystateCommand.NEXT_TRACK -> playNextUp()
PlaystateCommand.PREVIOUS_TRACK -> playPrevious() PlaystateCommand.PREVIOUS_TRACK -> playPrevious()
PlaystateCommand.SEEK -> it.seekPositionTicks?.ticks?.let { player.seekTo(it.inWholeMilliseconds) } PlaystateCommand.SEEK -> it.seekPositionTicks?.ticks?.let { player.seekTo(it.inWholeMilliseconds) }
PlaystateCommand.REWIND -> PlaystateCommand.REWIND ->
@ -1111,6 +1102,7 @@ class PlaybackViewModel
} }
data class CurrentPlayback( data class CurrentPlayback(
val itemId: UUID,
val backend: PlayerBackend, val backend: PlayerBackend,
val tracks: List<TrackSupport>, val tracks: List<TrackSupport>,
val playMethod: PlayMethod, val playMethod: PlayMethod,