mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-07-26 14:38:39 +02:00
Fallback to session details if player has no active track.
Provides better handling if end of book has been reached.
This commit is contained in:
@@ -487,9 +487,17 @@ class AudioPlayer: NSObject {
|
||||
|
||||
public func getCurrentTime() -> Double? {
|
||||
guard let playbackSession = self.getPlaybackSession() else { return nil }
|
||||
let currentTrackTime = self.audioPlayer.currentTime().seconds
|
||||
let audioTrack = playbackSession.audioTracks[currentTrackIndex]
|
||||
let startOffset = audioTrack.startOffset ?? 0.0
|
||||
|
||||
// if the currentTrackTime is not a number, then track isn't loaded
|
||||
// fall back on session.
|
||||
var currentTrackTime = self.audioPlayer.currentTime().seconds
|
||||
if currentTrackTime.isNaN {
|
||||
if let currentChapter = playbackSession.getCurrentChapter() {
|
||||
currentTrackTime = currentChapter.getRelativeChapterCurrentTime(sessionCurrentTime:playbackSession.currentTime)
|
||||
}
|
||||
}
|
||||
return startOffset + currentTrackTime
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user