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

View file

@ -362,7 +362,14 @@ constructor(
} }
override fun playNext(songs: List<Song>, ack: StateAck.PlayNext) { 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) playbackManager.ack(this, ack)
deferSave() deferSave()
} }