Small improvements

This commit is contained in:
Rasmus Krämer
2022-05-03 12:55:13 +02:00
parent 394363c8cb
commit 9701c767b2
8 changed files with 86 additions and 66 deletions
+7 -8
View File
@@ -70,6 +70,7 @@ class AudioPlayer: NSObject {
public func destroy() {
// Pause is not synchronous causing this error on below lines:
// AVAudioSession_iOS.mm:1206 Deactivating an audio session that has running I/O. All I/O should be stopped or paused prior to deactivating the audio session
// It is related to L79 `AVAudioSession.sharedInstance().setActive(false)`
pause()
audioPlayer.replaceCurrentItem(with: nil)
@@ -80,11 +81,9 @@ class AudioPlayer: NSObject {
print(error)
}
// Throws error Possibly related to the error above
// DispatchQueue.main.sync {
// UIApplication.shared.endReceivingRemoteControlEvents()
// }
DispatchQueue.runOnMainQueue {
UIApplication.shared.endReceivingRemoteControlEvents()
}
NotificationCenter.default.post(name: NSNotification.Name(PlayerEvents.closed.rawValue), object: nil)
}
@@ -186,9 +185,9 @@ class AudioPlayer: NSObject {
// MARK: - Now playing
private func setupRemoteTransportControls() {
// DispatchQueue.main.sync {
DispatchQueue.runOnMainQueue {
UIApplication.shared.beginReceivingRemoteControlEvents()
// }
}
let commandCenter = MPRemoteCommandCenter.shared()
commandCenter.playCommand.isEnabled = true
@@ -246,7 +245,7 @@ class AudioPlayer: NSObject {
}
private func updateNowPlaying() {
NotificationCenter.default.post(name: NSNotification.Name(PlayerEvents.update.rawValue), object: nil)
NowPlayingInfo.update(duration: getDuration(), currentTime: getCurrentTime(), rate: rate)
NowPlayingInfo.shared.update(duration: getDuration(), currentTime: getCurrentTime(), rate: rate)
}
// MARK: - Observer