Respond to service failure

This commit is contained in:
Ali 2021-03-19 18:06:16 +04:00
parent dbc9f77d9b
commit a6c4ad95fc

View File

@ -219,11 +219,15 @@ public final class ManagedAudioSession {
}) })
NotificationCenter.default.addObserver(forName: AVAudioSession.interruptionNotification, object: AVAudioSession.sharedInstance(), queue: nil, using: { [weak self] notification in NotificationCenter.default.addObserver(forName: AVAudioSession.interruptionNotification, object: AVAudioSession.sharedInstance(), queue: nil, using: { [weak self] notification in
managedAudioSessionLog("Interruption received")
guard let info = notification.userInfo, guard let info = notification.userInfo,
let typeValue = info[AVAudioSessionInterruptionTypeKey] as? UInt, let typeValue = info[AVAudioSessionInterruptionTypeKey] as? UInt,
let type = AVAudioSession.InterruptionType(rawValue: typeValue) else { let type = AVAudioSession.InterruptionType(rawValue: typeValue) else {
return return
} }
managedAudioSessionLog("Interruption type: \(type)")
queue.async { queue.async {
if let strongSelf = self { if let strongSelf = self {
@ -233,6 +237,17 @@ public final class ManagedAudioSession {
} }
} }
}) })
NotificationCenter.default.addObserver(forName: AVAudioSession.mediaServicesWereLostNotification, object: AVAudioSession.sharedInstance(), queue: nil, using: { [weak self] _ in
managedAudioSessionLog("Media Services were lost")
queue.after(1.0, {
if let strongSelf = self {
if let (type, outputMode) = strongSelf.currentTypeAndOutputMode {
strongSelf.setup(type: type, outputMode: outputMode, activateNow: true)
}
}
})
})
queue.async { queue.async {
self.isHeadsetPluggedInValue = self.isHeadsetPluggedIn() self.isHeadsetPluggedInValue = self.isHeadsetPluggedIn()