diff --git a/ios/App/App/plugins/AbsAudioPlayer.swift b/ios/App/App/plugins/AbsAudioPlayer.swift index 1e5d0c62..536fd84f 100644 --- a/ios/App/App/plugins/AbsAudioPlayer.swift +++ b/ios/App/App/plugins/AbsAudioPlayer.swift @@ -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(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(onLocalMediaProgressUpdate), name: NSNotification.Name(PlayerEvents.localProgress.rawValue), object: nil) self.bridge?.webView?.allowsBackForwardNavigationGestures = true; @@ -186,8 +187,12 @@ public class AbsAudioPlayer: CAPPlugin { ]) } - @objc func onLocalMediaProgressUpdate(_ localMediaProgress: [String: Any]) { - self.notifyListeners("onLocalMediaProgressUpdate", data: localMediaProgress) + @objc func onLocalMediaProgressUpdate() { + 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() { diff --git a/ios/App/Shared/player/PlayerHandler.swift b/ios/App/Shared/player/PlayerHandler.swift index e6a7a8d8..16b0372a 100644 --- a/ios/App/Shared/player/PlayerHandler.swift +++ b/ios/App/Shared/player/PlayerHandler.swift @@ -201,7 +201,10 @@ class PlayerHandler { localMediaProgress.updateFromPlaybackSession(session) 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 } diff --git a/ios/App/Shared/util/PlayerEvents.swift b/ios/App/Shared/util/PlayerEvents.swift index 86bf801d..4b225a9e 100644 --- a/ios/App/Shared/util/PlayerEvents.swift +++ b/ios/App/Shared/util/PlayerEvents.swift @@ -13,4 +13,5 @@ enum PlayerEvents: String { case sleepSet = "com.audiobookshelf.app.player.sleep.set" case sleepEnded = "com.audiobookshelf.app.player.sleep.ended" case failed = "com.audiobookshelf.app.player.failed" + case localProgress = "com.audiobookshelf.app.player.localProgress" }