mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-27 22:04:08 +02:00
Sync local progress to front-end
This commit is contained in:
@@ -21,6 +21,7 @@ public class AbsAudioPlayer: CAPPlugin {
|
|||||||
NotificationCenter.default.addObserver(self, selector: #selector(sendSleepTimerSet), name: NSNotification.Name(PlayerEvents.sleepSet.rawValue), object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(sendSleepTimerSet), name: NSNotification.Name(PlayerEvents.sleepSet.rawValue), object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(sendSleepTimerEnded), name: NSNotification.Name(PlayerEvents.sleepEnded.rawValue), object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(sendSleepTimerEnded), name: NSNotification.Name(PlayerEvents.sleepEnded.rawValue), object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(onPlaybackFailed), name: NSNotification.Name(PlayerEvents.failed.rawValue), object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(onPlaybackFailed), name: NSNotification.Name(PlayerEvents.failed.rawValue), object: nil)
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(onLocalMediaProgressUpdate), name: NSNotification.Name(PlayerEvents.localProgress.rawValue), object: nil)
|
||||||
|
|
||||||
self.bridge?.webView?.allowsBackForwardNavigationGestures = true;
|
self.bridge?.webView?.allowsBackForwardNavigationGestures = true;
|
||||||
|
|
||||||
@@ -186,8 +187,12 @@ public class AbsAudioPlayer: CAPPlugin {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func onLocalMediaProgressUpdate(_ localMediaProgress: [String: Any]) {
|
@objc func onLocalMediaProgressUpdate() {
|
||||||
self.notifyListeners("onLocalMediaProgressUpdate", data: localMediaProgress)
|
guard let localMediaProgressId = PlayerHandler.getPlaybackSession()?.localMediaProgressId else { return }
|
||||||
|
guard let localMediaProgress = Database.shared.getLocalMediaProgress(localMediaProgressId: localMediaProgressId) else { return }
|
||||||
|
guard let progressUpdate = try? localMediaProgress.asDictionary() else { return }
|
||||||
|
NSLog("Sending local progress back to the UI")
|
||||||
|
self.notifyListeners("onLocalMediaProgressUpdate", data: progressUpdate)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func onPlaybackFailed() {
|
@objc func onPlaybackFailed() {
|
||||||
|
|||||||
@@ -201,7 +201,10 @@ class PlayerHandler {
|
|||||||
localMediaProgress.updateFromPlaybackSession(session)
|
localMediaProgress.updateFromPlaybackSession(session)
|
||||||
Database.shared.saveLocalMediaProgress(localMediaProgress)
|
Database.shared.saveLocalMediaProgress(localMediaProgress)
|
||||||
|
|
||||||
// TODO: Send local media progress back to UI
|
NSLog("Local progress saved to the database")
|
||||||
|
|
||||||
|
// Send the local progress back to front-end
|
||||||
|
NotificationCenter.default.post(name: NSNotification.Name(PlayerEvents.localProgress.rawValue), object: nil)
|
||||||
|
|
||||||
return localMediaProgress
|
return localMediaProgress
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,4 +13,5 @@ enum PlayerEvents: String {
|
|||||||
case sleepSet = "com.audiobookshelf.app.player.sleep.set"
|
case sleepSet = "com.audiobookshelf.app.player.sleep.set"
|
||||||
case sleepEnded = "com.audiobookshelf.app.player.sleep.ended"
|
case sleepEnded = "com.audiobookshelf.app.player.sleep.ended"
|
||||||
case failed = "com.audiobookshelf.app.player.failed"
|
case failed = "com.audiobookshelf.app.player.failed"
|
||||||
|
case localProgress = "com.audiobookshelf.app.player.localProgress"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user