From fa9780722f651097c21e67720e05d5e840ab11cd Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Thu, 15 Sep 2022 14:08:15 +0800 Subject: [PATCH] Only update nowPlaying data if the timeElapsed is accurately calculated --- .../Services/AudioSession/AudioController.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/apple/OmnivoreKit/Sources/Services/AudioSession/AudioController.swift b/apple/OmnivoreKit/Sources/Services/AudioSession/AudioController.swift index 7382bab0e..18816431e 100644 --- a/apple/OmnivoreKit/Sources/Services/AudioSession/AudioController.swift +++ b/apple/OmnivoreKit/Sources/Services/AudioSession/AudioController.swift @@ -458,17 +458,19 @@ public class AudioController: NSObject, ObservableObject, AVAudioPlayerDelegate let itemElapsed = playerItem.status == .readyToPlay ? CMTimeGetSeconds(playerItem.currentTime()) : 0 timeElapsed = durationBefore(playerIndex: playerItem.speechItem.audioIdx) + itemElapsed timeElapsedString = formatTimeInterval(timeElapsed) - } - if var nowPlaying = MPNowPlayingInfoCenter.default().nowPlayingInfo { - nowPlaying[MPMediaItemPropertyPlaybackDuration] = NSNumber(value: duration) - nowPlaying[MPNowPlayingInfoPropertyElapsedPlaybackTime] = NSNumber(value: timeElapsed) - MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlaying + + if var nowPlaying = MPNowPlayingInfoCenter.default().nowPlayingInfo { + nowPlaying[MPMediaItemPropertyPlaybackDuration] = NSNumber(value: duration) + nowPlaying[MPNowPlayingInfoPropertyElapsedPlaybackTime] = NSNumber(value: timeElapsed) + MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlaying + } } case .scrubStarted: break case let .scrubEnded(seekTime): scrubState = .reset timeElapsed = seekTime + timeElapsedString = formatTimeInterval(timeElapsed) } }