mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-28 05:53:59 +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:
parent
c72f7cddc8
commit
78d7ba69df
1 changed files with 9 additions and 1 deletions
|
@ -487,9 +487,17 @@ class AudioPlayer: NSObject {
|
||||||
|
|
||||||
public func getCurrentTime() -> Double? {
|
public func getCurrentTime() -> Double? {
|
||||||
guard let playbackSession = self.getPlaybackSession() else { return nil }
|
guard let playbackSession = self.getPlaybackSession() else { return nil }
|
||||||
let currentTrackTime = self.audioPlayer.currentTime().seconds
|
|
||||||
let audioTrack = playbackSession.audioTracks[currentTrackIndex]
|
let audioTrack = playbackSession.audioTracks[currentTrackIndex]
|
||||||
let startOffset = audioTrack.startOffset ?? 0.0
|
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
|
return startOffset + currentTrackTime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue