ios – Handle interruptions during a phone call, the “begin” works but the “ended” doesn’t


The application uses AVPlayer for streaming audio from URLs. When the device is in a low-volume, we pause the player with avplayer.pause(). We aim to implement audio interruption handling during a phone call.
Although the app successfully detects a phone call .begin state , it fails to recognize that the interruption has ended state only when only the AVPlayer is paused.

 @objc func handleInterruption(notification: Notification) {
    guard let userInfo = notification.userInfo else { return }
    if let typeValue = userInfo[AVAudioSessionInterruptionTypeKey] as? UInt, let type = AVAudioSession.InterruptionType(rawValue: typeValue) {
        switch type {
        case .began:
            print("begun")
        case .ended:
            print("ended")
        }
    }
}

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img