diff --git a/ios/App/Shared/player/AudioPlayer.swift b/ios/App/Shared/player/AudioPlayer.swift index a0a56aede..877f61a8e 100644 --- a/ios/App/Shared/player/AudioPlayer.swift +++ b/ios/App/Shared/player/AudioPlayer.swift @@ -56,8 +56,6 @@ class AudioPlayer: NSObject { internal var currentTrackIndex = 0 private var allPlayerItems:[AVPlayerItem] = [] - private var pausedTimer: Timer? - // MARK: - Constructor init(sessionId: String, playWhenReady: Bool = false, playbackRate: Float = 1) { self.playWhenReady = playWhenReady @@ -159,7 +157,6 @@ class AudioPlayer: NSObject { NotificationCenter.default.post(name: NSNotification.Name(PlayerEvents.closed.rawValue), object: nil) // Remove timers - self.stopPausedTimer() self.removeSleepTimer() } @@ -301,21 +298,6 @@ class AudioPlayer: NSObject { } } - private func startPausedTimer() { - guard self.pausedTimer == nil else { return } - self.queue.async { - self.pausedTimer = Timer.scheduledTimer(withTimeInterval: 10, repeats: true) { [weak self] timer in - self?.logger.log("PAUSE TIMER: Syncing from server") - Task { await PlayerProgress.shared.syncFromServer() } - } - } - } - - private func stopPausedTimer() { - self.pausedTimer?.invalidate() - self.pausedTimer = nil - } - // MARK: - Methods public func play(allowSeekBack: Bool = false, isInitializing: Bool = false) { guard self.isInitialized() || isInitializing else { return } @@ -345,9 +327,6 @@ class AudioPlayer: NSObject { private func resumePlayback() { logger.log("PLAY: Resuming playback") - // Stop the paused timer - self.stopPausedTimer() - self.markAudioSessionAs(active: true) DispatchQueue.runOnMainQueue { self.audioPlayer.play() @@ -380,8 +359,6 @@ class AudioPlayer: NSObject { self.status = .paused updateNowPlaying() - - self.startPausedTimer() } public func seek(_ to: Double, from: String) { diff --git a/ios/App/Shared/player/PlayerProgress.swift b/ios/App/Shared/player/PlayerProgress.swift index 18f63719d..f3c88df8f 100644 --- a/ios/App/Shared/player/PlayerProgress.swift +++ b/ios/App/Shared/player/PlayerProgress.swift @@ -36,17 +36,6 @@ class PlayerProgress { await UIApplication.shared.endBackgroundTask(backgroundToken) } - public func syncFromServer() async { - let backgroundToken = await UIApplication.shared.beginBackgroundTask(withName: "ABS:syncFromServer") - do { - try await updateLocalSessionFromServerMediaProgress() - } catch { - logger.error("Failed to syncFromServer") - logger.error(error) - } - await UIApplication.shared.endBackgroundTask(backgroundToken) - } - // MARK: - SYNC LOGIC @@ -164,6 +153,7 @@ class PlayerProgress { } } + // TODO: Unused for now private func updateLocalSessionFromServerMediaProgress() async throws { logger.log("updateLocalSessionFromServerMediaProgress: Checking if local media progress was updated on server") guard let session = try Realm(queue: nil).objects(PlaybackSession.self).last(where: { diff --git a/ios/App/Shared/util/ApiClient.swift b/ios/App/Shared/util/ApiClient.swift index cd498ac21..44e0ddcf4 100644 --- a/ios/App/Shared/util/ApiClient.swift +++ b/ios/App/Shared/util/ApiClient.swift @@ -236,8 +236,10 @@ class ApiClient { if (success) { // Remove sessions from db try playbackSessions.forEach { session in - if let session = session.thaw() { - try session.delete() + if (!session.isActiveSession) { + if let session = session.thaw() { + try session.delete() + } } } }