From b075f8ec517ef0a28480c763e36d9db85b07ddbe 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. --- .../playback/service/PlaybackServiceFragment.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/oxycblt/auxio/playback/service/PlaybackServiceFragment.kt b/app/src/main/java/org/oxycblt/auxio/playback/service/PlaybackServiceFragment.kt index ee2d281ed..d3d41f61e 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/service/PlaybackServiceFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/service/PlaybackServiceFragment.kt @@ -362,7 +362,17 @@ constructor( } 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() })