silenceSecondaryAudioHintNotification
A notification the system posts when the primary audio from other apps starts and stops.
Declaration
class let silenceSecondaryAudioHintNotification: NSNotification.NameDiscussion
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.