Global Variable

AVAudioSessionSilenceSecondaryAudioHintNotification

A notification that’s posted when the primary audio from other applications starts and stops.

Declaration

const NSNotificationName AVAudioSessionSilenceSecondaryAudioHintNotification;

Discussion

Subscribe to this notification to ensure that the system notifies your app when optional secondary audio muting should begin or end. The system sends this notification only to registered listeners who are currently in the foreground and have an active audio session.

This notification’s userInfo dictionary contains a AVAudioSessionSilenceSecondaryAudioHintType value for the AVAudioSessionSilenceSecondaryAudioHintTypeKey. Use the audio hint type to determine if your secondary audio muting should begin or end.

func handleSecondaryAudio(notification: Notification) {
    // Determine hint type
    guard let userInfo = notification.userInfo,
        let typeValue = userInfo[AVAudioSessionSilenceSecondaryAudioHintTypeKey] as? UInt,
        let type = AVAudioSession.SilenceSecondaryAudioHintType(rawValue: typeValue) else {
            return
    }
    
    if type == .begin {
        // Other app audio started playing - mute secondary audio.
    } else {
        // Other app audio stopped playing - restart secondary audio.
    }
}

The system posts this notification on the main thread.

Topics

User Info Keys

AVAudioSessionSilenceSecondaryAudioHintTypeKey

A user info key that you use to retrieve the silence secondary audio hint type.

User Info Values

AVAudioSessionSilenceSecondaryAudioHintType

Constants that indicate whether optional secondary audio muting should begin or end.

See Also

Responding to Audio Session Notifications

Responding to Audio Session Interruptions

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

Responding to Audio Session Route Changes

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

AVAudioSessionInterruptionNotification

A notification that’s posted when an audio interruption occurs.

Interruption Flags

Constants that indicate the state of the audio session following an interruption.

AVAudioSessionRouteChangeNotification

A notification that’s posted when the system’s audio route changes.

AVAudioSessionMediaServicesWereLostNotification

A notification that’s posted when the system terminates the media server.

AVAudioSessionMediaServicesWereResetNotification

A notification that’s posted when the media server restarts.