mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-07-21 19:25:00 +02:00
Fix: Extra timeListening when player initializes
This commit is contained in:
parent
91dbd73d45
commit
711b079963
1 changed files with 11 additions and 5 deletions
|
@ -145,9 +145,11 @@ class AudioPlayer: NSObject {
|
|||
let seconds = 0.5 * (self.rate > 0 ? self.rate : 1.0)
|
||||
let time = CMTime(seconds: Double(seconds), preferredTimescale: timeScale)
|
||||
self.timeObserverToken = self.audioPlayer.addPeriodicTimeObserver(forInterval: time, queue: self.queue) { [weak self] time in
|
||||
let isPlaying = self?.isPlaying() ?? false
|
||||
|
||||
Task {
|
||||
// Let the player update the current playback positions
|
||||
await PlayerProgress.shared.syncFromPlayer(currentTime: time.seconds, includesPlayProgress: true, isStopping: false)
|
||||
await PlayerProgress.shared.syncFromPlayer(currentTime: time.seconds, includesPlayProgress: isPlaying, isStopping: false)
|
||||
}
|
||||
|
||||
// Update the sleep time, if set
|
||||
|
@ -257,8 +259,7 @@ class AudioPlayer: NSObject {
|
|||
self.stopPausedTimer()
|
||||
|
||||
Task {
|
||||
let isPlaying = self.status > 0
|
||||
await PlayerProgress.shared.syncFromPlayer(currentTime: self.getCurrentTime(), includesPlayProgress: isPlaying, isStopping: false)
|
||||
await PlayerProgress.shared.syncFromPlayer(currentTime: self.getCurrentTime(), includesPlayProgress: self.isPlaying(), isStopping: false)
|
||||
}
|
||||
|
||||
self.audioPlayer.play()
|
||||
|
@ -278,8 +279,7 @@ class AudioPlayer: NSObject {
|
|||
self.audioPlayer.pause()
|
||||
|
||||
Task {
|
||||
let wasPlaying = self.status > 0
|
||||
await PlayerProgress.shared.syncFromPlayer(currentTime: self.getCurrentTime(), includesPlayProgress: wasPlaying, isStopping: true)
|
||||
await PlayerProgress.shared.syncFromPlayer(currentTime: self.getCurrentTime(), includesPlayProgress: self.isPlaying(), isStopping: true)
|
||||
}
|
||||
|
||||
self.status = 0
|
||||
|
@ -495,14 +495,20 @@ class AudioPlayer: NSObject {
|
|||
let playbackSession = Database.shared.getPlaybackSession(id: self.sessionId)!
|
||||
return playbackSession.playMethod
|
||||
}
|
||||
|
||||
public func getPlaybackSessionId() -> String {
|
||||
return self.sessionId
|
||||
}
|
||||
|
||||
public func getDuration() -> Double {
|
||||
let playbackSession = Database.shared.getPlaybackSession(id: self.sessionId)!
|
||||
return playbackSession.duration
|
||||
}
|
||||
|
||||
public func isPlaying() -> Bool {
|
||||
return self.status > 0
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
private func createAsset(itemId:String, track:AudioTrack) -> AVAsset {
|
||||
let playbackSession = Database.shared.getPlaybackSession(id: self.sessionId)!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue