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:
parent
24faeef8f3
commit
c6b960466b
1 changed files with 8 additions and 1 deletions
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue