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 committed by Alexander Capehart
parent e0352a105a
commit b075f8ec51
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47

View file

@ -362,7 +362,17 @@ constructor(
} }
override fun playNext(songs: List<Song>, ack: StateAck.PlayNext) { 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) { if (nextIndex == C.INDEX_UNSET) {
player.addMediaItems(songs.map { it.toMediaItem() }) player.addMediaItems(songs.map { it.toMediaItem() })