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.
This commit is contained in:
unrenowned 2024-03-29 14:40:42 +00:00
parent c6b960466b
commit 1d9dc34549
No known key found for this signature in database

View file

@ -377,7 +377,17 @@ class PlaybackService :
}
override fun playNext(songs: List<Song>, 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() })