Type Property

silenceSecondaryAudioHintNotification

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

Declaration

class let silenceSecondaryAudioHintNotification: NSNotification.Name

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 AVAudioSession.SilenceSecondaryAudioHintType 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

let AVAudioSessionSilenceSecondaryAudioHintTypeKey: String

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

User Info Values

enum AVAudioSession.SilenceSecondaryAudioHintType

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.

class let interruptionNotification: NSNotification.Name

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

class let routeChangeNotification: NSNotification.Name

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

class let mediaServicesWereLostNotification: NSNotification.Name

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

class let mediaServicesWereResetNotification: NSNotification.Name

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