Merge pull request #748 from unrenowned/bugfix/playnext-crash

Fix Crashes/Bugs when Play Next is used at the end of a queue
This commit is contained in:
Alexander Capehart 2024-03-29 17:06:07 +00:00 committed by GitHub
commit 821f043cfe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -377,7 +377,24 @@ class PlaybackService :
}
override fun playNext(songs: List<Song>, ack: StateAck.PlayNext) {
player.addMediaItems(player.nextMediaItemIndex, songs.map { it.toMediaItem() })
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() })
} else {
player.addMediaItems(nextIndex, songs.map { it.toMediaItem() })
}
playbackManager.ack(this, ack)
deferSave()
}