mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-28 14:17:19 +02:00
Fix: Extra timeListening when player initializes
This commit is contained in:
@@ -145,9 +145,11 @@ class AudioPlayer: NSObject {
|
|||||||
let seconds = 0.5 * (self.rate > 0 ? self.rate : 1.0)
|
let seconds = 0.5 * (self.rate > 0 ? self.rate : 1.0)
|
||||||
let time = CMTime(seconds: Double(seconds), preferredTimescale: timeScale)
|
let time = CMTime(seconds: Double(seconds), preferredTimescale: timeScale)
|
||||||
self.timeObserverToken = self.audioPlayer.addPeriodicTimeObserver(forInterval: time, queue: self.queue) { [weak self] time in
|
self.timeObserverToken = self.audioPlayer.addPeriodicTimeObserver(forInterval: time, queue: self.queue) { [weak self] time in
|
||||||
|
let isPlaying = self?.isPlaying() ?? false
|
||||||
|
|
||||||
Task {
|
Task {
|
||||||
// Let the player update the current playback positions
|
// 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
|
// Update the sleep time, if set
|
||||||
@@ -257,8 +259,7 @@ class AudioPlayer: NSObject {
|
|||||||
self.stopPausedTimer()
|
self.stopPausedTimer()
|
||||||
|
|
||||||
Task {
|
Task {
|
||||||
let isPlaying = self.status > 0
|
await PlayerProgress.shared.syncFromPlayer(currentTime: self.getCurrentTime(), includesPlayProgress: self.isPlaying(), isStopping: false)
|
||||||
await PlayerProgress.shared.syncFromPlayer(currentTime: self.getCurrentTime(), includesPlayProgress: isPlaying, isStopping: false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.audioPlayer.play()
|
self.audioPlayer.play()
|
||||||
@@ -278,8 +279,7 @@ class AudioPlayer: NSObject {
|
|||||||
self.audioPlayer.pause()
|
self.audioPlayer.pause()
|
||||||
|
|
||||||
Task {
|
Task {
|
||||||
let wasPlaying = self.status > 0
|
await PlayerProgress.shared.syncFromPlayer(currentTime: self.getCurrentTime(), includesPlayProgress: self.isPlaying(), isStopping: true)
|
||||||
await PlayerProgress.shared.syncFromPlayer(currentTime: self.getCurrentTime(), includesPlayProgress: wasPlaying, isStopping: true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.status = 0
|
self.status = 0
|
||||||
@@ -495,14 +495,20 @@ class AudioPlayer: NSObject {
|
|||||||
let playbackSession = Database.shared.getPlaybackSession(id: self.sessionId)!
|
let playbackSession = Database.shared.getPlaybackSession(id: self.sessionId)!
|
||||||
return playbackSession.playMethod
|
return playbackSession.playMethod
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getPlaybackSessionId() -> String {
|
public func getPlaybackSessionId() -> String {
|
||||||
return self.sessionId
|
return self.sessionId
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getDuration() -> Double {
|
public func getDuration() -> Double {
|
||||||
let playbackSession = Database.shared.getPlaybackSession(id: self.sessionId)!
|
let playbackSession = Database.shared.getPlaybackSession(id: self.sessionId)!
|
||||||
return playbackSession.duration
|
return playbackSession.duration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func isPlaying() -> Bool {
|
||||||
|
return self.status > 0
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Private
|
// MARK: - Private
|
||||||
private func createAsset(itemId:String, track:AudioTrack) -> AVAsset {
|
private func createAsset(itemId:String, track:AudioTrack) -> AVAsset {
|
||||||
let playbackSession = Database.shared.getPlaybackSession(id: self.sessionId)!
|
let playbackSession = Database.shared.getPlaybackSession(id: self.sessionId)!
|
||||||
|
|||||||
Reference in New Issue
Block a user