playback: fix playNext crash on last song of queue

Fixes OxygenCobalt/Auxio#735. ExoPlayer method for fetching next media
item returns C.INDEX_UNSET (-1) when used on the last song of a queue,
which is not a valid index for ExoPlayer.addMediaItems(). New code just
adds songs to the end of the queue if there isn't a next song.
This commit is contained in:
unrenowned 2024-03-29 14:27:18 +00:00
parent 24faeef8f3
commit c6b960466b
No known key found for this signature in database

View file

@ -377,7 +377,14 @@ class PlaybackService :
}
override fun playNext(songs: List<Song>, ack: StateAck.PlayNext) {
player.addMediaItems(player.nextMediaItemIndex, songs.map { it.toMediaItem() })
val nextIndex = player.nextMediaItemIndex
if (nextIndex == C.INDEX_UNSET) {
player.addMediaItems(songs.map { it.toMediaItem() })
} else {
player.addMediaItems(nextIndex, songs.map { it.toMediaItem() })
}
playbackManager.ack(this, ack)
deferSave()
}