don't crash with index out of range when removing radios from saved play queue

This commit is contained in:
Drew Weymouth
2024-06-02 08:46:07 -07:00
parent 8de689dee4
commit 0d848aecbd
2 changed files with 8 additions and 1 deletions
+1 -1
View File
@@ -378,7 +378,7 @@ func (a *App) LoadSavedPlayQueue() error {
if err := a.PlaybackManager.LoadTracks(queue.Tracks, Replace, false); err != nil {
return err
}
if queue.TrackIndex >= 0 {
if queue.TrackIndex >= 0 && queue.TrackIndex < len(queue.Tracks) {
// TODO: This isn't ideal but doesn't seem to cause an audible play-for-a-split-second artifact
a.PlaybackManager.PlayTrackAt(queue.TrackIndex)
a.PlaybackManager.Pause()
+7
View File
@@ -36,6 +36,13 @@ func SavePlayQueue(serverID string, pm *PlaybackManager, filepath string, server
trackIDs = append(trackIDs, item.Metadata().ID)
}
}
if l := len(trackIDs); trackIdx >= l {
if l == 0 {
trackIdx = 0
} else {
trackIdx = l - 1
}
}
saved := serializedSavedPlayQueue{
ServerID: serverID,