From 1d9dc345494c59e82eb77894631c979726e856de Mon Sep 17 00:00:00 2001 From: unrenowned <163776820+unrenowned@users.noreply.github.com> Date: Fri, 29 Mar 2024 14:40:42 +0000 Subject: [PATCH] playback: fix playNext wraparound with Repeat All ExoPlayer method for fetching next media item respects Repeat All, which on the last song of a queue causes playNext to wrap around and insert the songs at the start of the queue. New code fetches next song as if repeat were turned off, so the songs will always be added to the end of the queue. --- .../oxycblt/auxio/playback/system/PlaybackService.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/oxycblt/auxio/playback/system/PlaybackService.kt b/app/src/main/java/org/oxycblt/auxio/playback/system/PlaybackService.kt index 997e355a9..19b7136a8 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/system/PlaybackService.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/system/PlaybackService.kt @@ -377,7 +377,17 @@ class PlaybackService : } override fun playNext(songs: List, ack: StateAck.PlayNext) { - val nextIndex = player.nextMediaItemIndex + val currTimeline = player.currentTimeline + val nextIndex = + if (currTimeline.isEmpty) { + C.INDEX_UNSET + } else { + currTimeline.getNextWindowIndex( + player.currentMediaItemIndex, + Player.REPEAT_MODE_OFF, + player.shuffleModeEnabled + ) + } if (nextIndex == C.INDEX_UNSET) { player.addMediaItems(songs.map { it.toMediaItem() })