mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-01 16:44:41 +02:00
fix: seek when changing track
This commit is contained in:
parent
c9ad0c7897
commit
3318f3501c
1 changed files with 20 additions and 11 deletions
|
@ -161,6 +161,9 @@ class AudioPlayer: NSObject {
|
||||||
let trackEnd = startOffset + duration
|
let trackEnd = startOffset + duration
|
||||||
if (time < trackEnd.rounded(.down)) {
|
if (time < trackEnd.rounded(.down)) {
|
||||||
return index
|
return index
|
||||||
|
} else if (index == self.allPlayerItems.count - 1) {
|
||||||
|
// Seeking past end of last item
|
||||||
|
return index
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
|
@ -368,11 +371,6 @@ class AudioPlayer: NSObject {
|
||||||
|
|
||||||
guard let playbackSession = self.getPlaybackSession() else { return }
|
guard let playbackSession = self.getPlaybackSession() else { return }
|
||||||
|
|
||||||
let currentTrack = playbackSession.audioTracks[self.currentTrackIndex]
|
|
||||||
let ctso = currentTrack.startOffset ?? 0.0
|
|
||||||
let trackEnd = ctso + currentTrack.duration
|
|
||||||
logger.log("SEEK: Seek current track END = \(trackEnd)")
|
|
||||||
|
|
||||||
let indexOfSeek = getItemIndexForTime(time: to)
|
let indexOfSeek = getItemIndexForTime(time: to)
|
||||||
logger.log("SEEK: Seek to index \(indexOfSeek) | Current index \(self.currentTrackIndex)")
|
logger.log("SEEK: Seek to index \(indexOfSeek) | Current index \(self.currentTrackIndex)")
|
||||||
|
|
||||||
|
@ -393,11 +391,22 @@ class AudioPlayer: NSObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
seekInCurrentTrack(to: to, playbackSession: playbackSession)
|
||||||
|
|
||||||
setupQueueItemStatusObserver()
|
setupQueueItemStatusObserver()
|
||||||
} else {
|
} else {
|
||||||
logger.log("SEEK: Seeking in current item \(to)")
|
seekInCurrentTrack(to: to, playbackSession: playbackSession)
|
||||||
let currentTrackStartOffset = playbackSession.audioTracks[self.currentTrackIndex].startOffset ?? 0.0
|
}
|
||||||
let seekTime = to - currentTrackStartOffset
|
|
||||||
|
// Only for use in here where we handle track selection
|
||||||
|
func seekInCurrentTrack(to: Double, playbackSession: PlaybackSession) {
|
||||||
|
let currentTrack = playbackSession.audioTracks[self.currentTrackIndex]
|
||||||
|
let ctso = currentTrack.startOffset ?? 0.0
|
||||||
|
let trackEnd = ctso + currentTrack.duration
|
||||||
|
logger.log("SEEK: Seeking in current item \(to) (track START = \(ctso) END = \(trackEnd))")
|
||||||
|
|
||||||
|
let boundedTime = min(max(to, ctso), trackEnd)
|
||||||
|
let seekTime = boundedTime - ctso
|
||||||
|
|
||||||
DispatchQueue.runOnMainQueue {
|
DispatchQueue.runOnMainQueue {
|
||||||
self.audioPlayer.seek(to: CMTime(seconds: seekTime, preferredTimescale: 1000)) { [weak self] completed in
|
self.audioPlayer.seek(to: CMTime(seconds: seekTime, preferredTimescale: 1000)) { [weak self] completed in
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue