mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-12-05 22:36:29 +01:00
Refactor to ensure we aren't missing any update time
This commit is contained in:
1 parent
6257c6488b
commit
50f6b15d23
1 file changed
+8
-8
@@ -194,18 +194,18 @@ class AudioPlayer: NSObject {
|
||||
}
|
||||
|
||||
private func setupQueueItemStatusObserver() {
|
||||
NSLog("queueStatusObserver: Setting up")
|
||||
|
||||
// Listen for player item updates
|
||||
self.queueItemStatusObserver?.invalidate()
|
||||
let status = self.audioPlayer.currentItem?.status.rawValue ?? -1
|
||||
|
||||
NSLog("queueStatusObserver: Setting up status=\(status)")
|
||||
// First item already loaded, we need to fire manually
|
||||
if status == 1, let playerItem = self.audioPlayer.currentItem {
|
||||
self.handleQueueItemStatus(playerItem: playerItem)
|
||||
}
|
||||
// Now listen for future updates
|
||||
self.queueItemStatusObserver = self.audioPlayer.currentItem?.observe(\.status, options: [.new, .old], changeHandler: { playerItem, change in
|
||||
self.handleQueueItemStatus(playerItem: playerItem)
|
||||
})
|
||||
|
||||
// Ensure we didn't miss a player item update during initialization
|
||||
if let playerItem = self.audioPlayer.currentItem {
|
||||
self.handleQueueItemStatus(playerItem: playerItem)
|
||||
}
|
||||
}
|
||||
|
||||
private func handleQueueItemStatus(playerItem: AVPlayerItem) {
|
||||
|
||||
Reference in new issue
Block a user