Global Variable

AVAudioSessionSilenceSecondaryAudioHintNotification

Posted when the primary audio from other applications starts and stops.

Declaration

const NSNotificationName AVAudioSessionSilenceSecondaryAudioHintNotification;

Discussion

Subscribe to this notification to ensure that your app is notified when optional secondary audio muting should begin or end. This notification is sent only to registered listeners that 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.

Listing 1

Responding to Secondary Audio Hint Notifications

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

This notification is posted on the main thread.

Topics

User Info Keys

AVAudioSessionSilenceSecondaryAudioHintTypeKey

User info key to retrieve the silence secondary audio hint type.

User Info Values

AVAudioSessionSilenceSecondaryAudioHintType

These constants are returned by AVAudioSessionSilenceSecondaryAudioHintType to indicate whether optional secondary audio muting should begin or end

See Also

Responding to Audio Session Notifications

Responding to Audio Session Interruptions

Directly observe audio session notifications to ensure that your app responds to interruptions.

Responding to Audio Session Route Changes

Directly observe audio session notifications to ensure that your app responds to interruptions.

AVAudioSessionInterruptionNotification

Posted when an audio interruption occurs.

AVAudioSessionRouteChangeNotification

Posted when the system’s audio route changes.

AVAudioSessionMediaServicesWereLostNotification

Posted when the media server is terminated.

AVAudioSessionMediaServicesWereResetNotification

Posted when the media server restarts.