mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-06 11:04:52 +02:00
Fix player session restoration events
This commit is contained in:
parent
bf46c46fc0
commit
93cb27d324
7 changed files with 28 additions and 19 deletions
|
@ -9,6 +9,8 @@
|
|||
#import <Capacitor/Capacitor.h>
|
||||
|
||||
CAP_PLUGIN(AbsAudioPlayer, "AbsAudioPlayer",
|
||||
CAP_PLUGIN_METHOD(onReady, CAPPluginReturnNone);
|
||||
|
||||
CAP_PLUGIN_METHOD(prepareLibraryItem, CAPPluginReturnPromise);
|
||||
CAP_PLUGIN_METHOD(closePlayback, CAPPluginReturnPromise);
|
||||
|
||||
|
|
|
@ -23,18 +23,13 @@ public class AbsAudioPlayer: CAPPlugin {
|
|||
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)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(userInterfaceReady), name: NSNotification.Name(PlayerEvents.playerUserInterfaceReady.rawValue), object: nil)
|
||||
|
||||
self.bridge?.webView?.allowsBackForwardNavigationGestures = true;
|
||||
|
||||
}
|
||||
|
||||
@objc func userInterfaceReady() {
|
||||
if !self.isUIReady {
|
||||
NSLog("User interface is ready. Performing state restore...")
|
||||
self.restorePlaybackSession()
|
||||
self.isUIReady = true
|
||||
}
|
||||
@objc func onReady(_ call: CAPPluginCall) {
|
||||
self.restorePlaybackSession()
|
||||
}
|
||||
|
||||
func restorePlaybackSession() {
|
||||
|
@ -46,7 +41,7 @@ public class AbsAudioPlayer: CAPPlugin {
|
|||
let activeSession = try Realm().objects(PlaybackSession.self).where({ $0.isActiveSession == true }).last
|
||||
if let activeSession = activeSession {
|
||||
try self.startPlaybackSession(activeSession, playWhenReady: false, playbackRate: PlayerSettings.main().playbackRate)
|
||||
PlayerHandler.syncServerProgressDuringPause()
|
||||
//PlayerHandler.syncServerProgressDuringPause()
|
||||
}
|
||||
} catch {
|
||||
NSLog("Failed to restore playback session")
|
||||
|
|
|
@ -155,10 +155,6 @@ public class AbsDatabase: CAPPlugin {
|
|||
call.reject("Failed to report synced media progress")
|
||||
}
|
||||
}
|
||||
|
||||
// If we're syncing progress with the server, we also have the UI ready
|
||||
// This will restore the player to the last playback session
|
||||
NotificationCenter.default.post(name: NSNotification.Name(PlayerEvents.playerUserInterfaceReady.rawValue), object: nil)
|
||||
}
|
||||
|
||||
@objc func syncServerMediaProgressWithLocalMediaProgress(_ call: CAPPluginCall) {
|
||||
|
|
|
@ -261,12 +261,6 @@ class AudioPlayer: NSObject {
|
|||
}
|
||||
|
||||
public func setPlaybackRate(_ rate: Float, observed: Bool = false) {
|
||||
// Handle a race condition on first launch
|
||||
guard self.status != -1 else {
|
||||
NSLog("Did not set playback rate as player is not initialized")
|
||||
return
|
||||
}
|
||||
|
||||
if self.audioPlayer.rate != rate {
|
||||
NSLog("setPlaybakRate rate changed from \(self.audioPlayer.rate) to \(rate)")
|
||||
self.audioPlayer.rate = rate
|
||||
|
|
|
@ -14,5 +14,4 @@ enum PlayerEvents: String {
|
|||
case sleepEnded = "com.audiobookshelf.app.player.sleep.ended"
|
||||
case failed = "com.audiobookshelf.app.player.failed"
|
||||
case localProgress = "com.audiobookshelf.app.player.localProgress"
|
||||
case playerUserInterfaceReady = "com.audiobookshelf.app.player.playerUserInterfaceReady"
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue