diff --git a/submodules/TelegramAudio/Sources/ManagedAudioSession.swift b/submodules/TelegramAudio/Sources/ManagedAudioSession.swift index 0ff25cbae8..16dadef996 100644 --- a/submodules/TelegramAudio/Sources/ManagedAudioSession.swift +++ b/submodules/TelegramAudio/Sources/ManagedAudioSession.swift @@ -219,11 +219,15 @@ public final class ManagedAudioSession { }) NotificationCenter.default.addObserver(forName: AVAudioSession.interruptionNotification, object: AVAudioSession.sharedInstance(), queue: nil, using: { [weak self] notification in + managedAudioSessionLog("Interruption received") + guard let info = notification.userInfo, let typeValue = info[AVAudioSessionInterruptionTypeKey] as? UInt, let type = AVAudioSession.InterruptionType(rawValue: typeValue) else { return } + + managedAudioSessionLog("Interruption type: \(type)") queue.async { 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 { self.isHeadsetPluggedInValue = self.isHeadsetPluggedIn()