<!--
{
  "documentType" : "article",
  "framework" : "AVFAudio",
  "identifier" : "/documentation/AVFAudio/handling-audio-interruptions",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Handling audio interruptions"
}
-->

# Handling audio interruptions

Observe audio session notifications to ensure that your app responds appropriately to interruptions.

## Discussion

Interruptions are a common part of the iOS and watchOS user experiences. For example, consider the scenario of receiving a phone call while you’re watching a movie in the TV app on your iPhone. In this case, the movie’s audio fades out, playback pauses, and the sound of the call’s ringtone fades in. If you decline the call, control returns to the TV app, and playback begins again as the movie’s audio fades in.

At the center of this behavior is your app’s audio session. As interruptions begin and end, the audio session notifies any registered observers so they can take appropriate action. For example, <doc://com.apple.documentation/documentation/AVFoundation/AVPlayer> monitors your app’s audio session and automatically pauses playback in response to interruption events. You can monitor these changes by key-value observing the player’s <doc://com.apple.documentation/documentation/AVFoundation/AVPlayer/timeControlStatus-swift.property> property, and update your user interface as necessary when the player pauses and resumes playback.

### Customize the interruption behavior

Most apps rely on the system’s default interruption behavior. However, [`AVAudioSession`](/documentation/AVFAudio/AVAudioSession) provides ways to customize the default behavior to better accommodate your app’s needs:

- Recent iPad models provide a feature that mutes the built-in microphone at the hardware level when the user closes the device’s Smart Folio cover. If your app plays and records audio, you may want to continue playback even if the system mutes the microphone. You can disable the default interruption behavior by setting the [`overrideMutedMicrophoneInterruption`](/documentation/AVFAudio/AVAudioSession/CategoryOptions-swift.struct/overrideMutedMicrophoneInterruption) option when configuring your audio session.
- System alerts, such as receiving an incoming phone call, interrupt the active audio session. If you prefer that the system not interrupt your app’s audio session in these cases, you can indicate this preference by setting a value for the [`setPrefersNoInterruptionsFromSystemAlerts(_:)`](/documentation/AVFAudio/AVAudioSession/setPrefersNoInterruptionsFromSystemAlerts(_:)) method.

### Observe audio session interruptions

You can directly observe interruption notifications that [`AVAudioSession`](/documentation/AVFAudio/AVAudioSession) posts. This might be useful if you want to know when the system pauses playback due to an interruption or another reason, such as a route change. To respond to audio interruptions, observe notifications of type [`interruptionNotification`](/documentation/AVFAudio/AVAudioSession/interruptionNotification).

```swift
func observeInterruptions() async {
    // Observe interruption notifications using async sequences.
    for await notification in NotificationCenter.default.notifications(
        named: AVAudioSession.interruptionNotification,
        object: AVAudioSession.sharedInstance()
    ) {
        handleInterruption(notification: notification)
    }
}

func handleInterruption(notification: Notification) {
    // To implement.
}
```

### Handle audio session interruptions

The posted <doc://com.apple.documentation/documentation/Foundation/Notification> object contains a populated user-information dictionary that provides the details of the interruption. You determine the type of interruption by retrieving the [`AVAudioSession.InterruptionType`](/documentation/AVFAudio/AVAudioSession/InterruptionType) value from the <doc://com.apple.documentation/documentation/Foundation/Notification/userInfo> dictionary. The interruption type indicates whether the interruption is beginning or ending.

```swift
func handleInterruption(notification: Notification) {
    guard let userInfo = notification.userInfo,
        let typeValue = userInfo[AVAudioSessionInterruptionTypeKey] as? UInt,
        let type = AVAudioSession.InterruptionType(rawValue: typeValue) else {
            return
    }

    // Switch over the interruption type.
    switch type {

    case .began:
        // An interruption began. Update the UI as necessary.

    case .ended:
       // An interruption ended. Resume playback, if appropriate.

        guard let optionsValue = userInfo[AVAudioSessionInterruptionOptionKey] as? UInt else { return }
        let options = AVAudioSession.InterruptionOptions(rawValue: optionsValue)
        if options.contains(.shouldResume) {
            // An interruption ended. Resume playback.
        } else {
            // An interruption ended. Don't resume playback.
        }

    default: ()
    }
}
```

If the interruption type is [`AVAudioSession.InterruptionType.ended`](/documentation/AVFAudio/AVAudioSession/InterruptionType/ended), the <doc://com.apple.documentation/documentation/Foundation/Notification/userInfo> dictionary contains an [`AVAudioSession.InterruptionOptions`](/documentation/AVFAudio/AVAudioSession/InterruptionOptions) value, which you use to determine whether playback automatically resumes.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)