The SharedAudioSession
interface provides a convenient way to manage and interact with the shared audio session in your script. The audio session acts as an intermediary between your script, the Scripting app, the operating system, and the underlying audio hardware, enabling you to configure and control audio behavior effectively.
category
Get the current audio session category.
categoryOptions
Retrieve the current audio session category options.
setCategory(category: AudioSessionCategory, options: AudioSessionCategoryOptions[])
Set the audio session category with specific options.
mode
Retrieve the current audio session mode.
setMode(mode: AudioSessionMode)
Set the audio session mode.
preferredSampleRate
Retrieve the preferred sample rate in hertz.
setPreferredSampleRate(sampleRate: number)
Set the preferred sample rate for audio input and output.
addInterruptionListener(listener: AudioSessionInterruptionListener)
Listen for audio interruptions.
removeInterruptionListener(listener: AudioSessionInterruptionListener)
Remove an interruption listener.
availableCategories
Get the list of audio session categories available on the device.
availableModes
Get the list of audio session modes available on the device.
isOtherAudioPlaying
Check if other audio is currently playing on the device.
secondaryAudioShouldBeSilencedHint
Check if secondary audio should be silenced.
allowHapticsAndSystemSoundsDuringRecording
Check if haptics and system sounds are allowed during recording.
prefersNoInterruptionsFromSystemAlerts
Check if the session prefers no interruptions from system alerts.
setActive(active: boolean)
Activate or deactivate the shared audio session.
setAllowHapticsAndSystemSoundsDuringRecording(value: boolean)
Enable or disable haptics and system sounds during recording.
setPrefersNoInterruptionsFromSystemAlerts(value: boolean)
Set the preference for no interruptions from system alerts.
Defines the session's audio category:
'ambient'
'multiRoute'
'playAndRecord'
'playback'
'record'
'soloAmbient'
Optional behaviors for audio categories:
'mixWithOthers'
'duckOthers'
'interruptSpokenAudioAndMixWithOthers'
'allowBluetooth'
'allowBluetoothA2DP'
'allowAirPlay'
'defaultToSpeaker'
'overrideMutedMicrophoneInterruption'
Specifies the session's mode:
'default'
'gameChat'
'measurement'
'moviePlayback'
'spokenAudio'
'videoChat'
'videoRecording'
'voiceChat'
'voicePrompt'
Specifies the type of interruption:
'began'
'ended'
'unknown'
This interface offers extensive control over audio session management in Scripting, making it suitable for building audio-heavy script like music players and video conferencing tools.