Rebuild track queue while seeking if player does not have a current track.

This commit is contained in:
Adam Traeger 2025-03-13 23:00:53 -05:00
parent 78d7ba69df
commit 45d3a15c68
No known key found for this signature in database
GPG key ID: 136E380CBA630639

View file

@ -424,6 +424,27 @@ class AudioPlayer: NSObject {
let indexOfSeek = getItemIndexForTime(time: to)
logger.log("SEEK: Seek to index \(indexOfSeek) | Current index \(self.currentTrackIndex)")
if self.audioPlayer.currentItem == nil {
self.currentTrackIndex = indexOfSeek
try? playbackSession.update {
playbackSession.currentTime = to
}
let playerItems = self.allPlayerItems[indexOfSeek..<self.allPlayerItems.count]
DispatchQueue.runOnMainQueue {
self.audioPlayer.removeAllItems()
for item in Array(playerItems) {
self.audioPlayer.insert(item, after:self.audioPlayer.items().last)
}
}
seekInCurrentTrack(to: to, playbackSession: playbackSession)
setupQueueItemStatusObserver()
return
}
// Reconstruct queue if seeking to a different track
if (self.currentTrackIndex != indexOfSeek) {
// When we seek to a different track, we need to make sure to seek the old track to 0