AVAudioSession Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/AVFoundation.framework |
| Availability | Available in iOS 3.0 and later. |
| Companion guide | |
| Declared in | AVAudioSession.h |
Overview
An instance of the AVAudioSession class, called an audio session, is a singleton object that you employ to set the audio context for your app. Use this class to:
Activate or deactivate your app’s audio session
Set the audio session category and mode
Specify your preferred audio hardware sample rate and I/O buffer duration
This class provides an Objective-C alternative to many features from the C-based Audio Session Services, described in Audio Session Services Reference. Certain audio session features, such as handling audio route changes and adjusting audio input gain, can be accessed only using Audio Session Services.
Starting in iOS 5.0, you can refine the device audio configuration provided by certain audio session categories by using an audio session mode. See “Audio Session Modes.”
Also starting in iOS 5.0, audio route information is dictionary based, giving you access to specific information on the input and output audio route, on audio route changes, and on audio routes available in a USB-attached audio accessory. See kAudioSessionProperty_AudioRouteDescription, kAudioSessionProperty_AudioRouteChange, kAudioSessionProperty_InputSources, and kAudioSessionProperty_OutputDestinations.
For more information on audio sessions, see Audio Session Programming Guide.
Tasks
Getting the Shared Audio Session
Managing an Audio Session
-
categoryproperty -
categoryOptionsproperty -
– setCategory:error: -
– setCategory:withOptions:error: -
modeproperty -
– setMode:error: -
– setActive:error: -
– setActive:withOptions:error: -
inputDataSourcesproperty -
inputDataSourceproperty -
– setInputDataSource:error: -
outputDataSourcesproperty -
outputDataSourceproperty -
– setOutputDataSource:error:
Working with Audio Channels
-
currentRouteproperty -
otherAudioPlayingproperty -
inputAvailableproperty -
inputNumberOfChannelsproperty -
outputNumberOfChannelsproperty -
sampleRateproperty -
preferredSampleRateproperty -
– setPreferredSampleRate:error: -
IOBufferDurationproperty -
preferredIOBufferDurationproperty -
– setPreferredIOBufferDuration:error: -
– overrideOutputAudioPort:error:
Accessing Latency and Gain Settings
-
outputVolumeproperty -
inputGainproperty -
inputGainSettableproperty -
– setInputGain:error: -
inputLatencyproperty -
outputLatencyproperty
Deprecated Properties and Methods
-
currentHardwareInputNumberOfChannelsproperty Deprecated in iOS 6.0 -
currentHardwareOutputNumberOfChannelsproperty Deprecated in iOS 6.0 -
currentHardwareSampleRateproperty Deprecated in iOS 6.0 -
delegateproperty Deprecated in iOS 6.0 -
inputIsAvailableproperty Deprecated in iOS 6.0 -
preferredHardwareSampleRateproperty Deprecated in iOS 6.0 -
– setActive:withFlags:error:Deprecated in iOS 6.0 -
– setPreferredHardwareSampleRate:error:Deprecated in iOS 6.0
Properties
category
The audio session category. (read-only)
Discussion
An audio session category is a key that identifies a set of audio behaviors for your app. An audio session has one of the categories listed in “Audio Session Categories.” The default category is AVAudioSessionCategorySoloAmbient. For more information, see Audio Session Programming Guide.
Availability
- Available in iOS 3.0 and later.
See Also
Declared In
AVAudioSession.hcategoryOptions
The options associated with the current category. (read-only)
Discussion
Category options allow you to tweak your app’s audio behavior in small ways. For a list of options that may be specified in this property, see “AVAudioSessionCategoryOptions”.
Availability
- Available in iOS 6.0 and later.
Declared In
AVAudioSession.hcurrentRoute
The current audio routing information. (read-only)
Discussion
The current audio route contains information about the input and output ports involved in the session. You can use the object in this property to retrieve those ports and get information about them.
Availability
- Available in iOS 6.0 and later.
Declared In
AVAudioSession.hinputAvailable
A Boolean value indicating whether an audio input path is available. (read-only)
Discussion
Use this property at launch time to determine whether the current device supports audio input. To respond to a change in the availability of audio input, register for the AVAudioSessionInputDidBecomeAvailableNotification and AVAudioSessionInputDidBecomeUnavailableNotification notifications.
This property contains the value YES if a path is available or NO if one is not.
Availability
- Available in iOS 6.0 and later.
Declared In
AVAudioSession.hinputDataSource
The currently selected input data source. (read-only)
Discussion
If there are no input data sources available, the value of this property will be nil. The value of this property must be an AVAudioSessionDataSourceDescription object from the inputDataSources property.
Availability
- Available in iOS 6.0 and later.
See Also
Declared In
AVAudioSession.hinputDataSources
An array of AVAudioSessionDataSourceDescription objects represeting the available input data sources for the audio session. (read-only)
Discussion
When there is an audio accessory that supports input data source selection, this property is populated with all of the available input data sources. This currently only applies to certain USB devices.
This property is also key-value observable so you can be informed when any changes are made to the array of input data sources.
Availability
- Available in iOS 6.0 and later.
Declared In
AVAudioSession.hinputGain
The gain applied to inputs associated with the session. (read-only)
Discussion
The value in this property is in the range 0.0 to 1.0, where 0.0 represents no additional gain and 1.0 represents the maximum possible gain.
You can observe changes to the value of this property using key-value observing.
Availability
- Available in iOS 6.0 and later.
Declared In
AVAudioSession.hinputGainSettable
A Boolean value indicating whether the input gain can be set. (read-only)
Discussion
Some inputs may not provide the ability to set the input gain, so it is important to check this property before attempting to set the input gain.
Availability
- Available in iOS 6.0 and later.
See Also
Declared In
AVAudioSession.hinputLatency
The latency for audio input, measured in seconds. (read-only)
Availability
- Available in iOS 6.0 and later.
Declared In
AVAudioSession.hinputNumberOfChannels
The number of audio input channels associated with the session. (read-only)
Availability
- Available in iOS 6.0 and later.
Declared In
AVAudioSession.hIOBufferDuration
The I/O buffer duration (in seconds) that is currently in effect. (read-only)
Availability
- Available in iOS 6.0 and later.
Declared In
AVAudioSession.hmode
The audio session mode. (read-only)
Discussion
An audio session mode is a key that identifies a set of device audio configuration details, such as whether or not the device performs automatic gain adjustment on incoming audio. A mode refines the configuration provided by a category. An audio session has one of the modes listed in “Audio Session Modes.” The default mode is AVAudioSessionModeDefault.
Availability
- Available in iOS 5.0 and later.
Declared In
AVAudioSession.hotherAudioPlaying
A Boolean value indicating whether another app is currently playing audio. (read-only)
Availability
- Available in iOS 6.0 and later.
Declared In
AVAudioSession.houtputDataSource
The currently selected output data source. (read-only)
Discussion
If there are no output data sources available, the value of this property will be nil. The value of this property must be an AVAudioSessionDataSourceDescription object from the outputDataSources property.
Availability
- Available in iOS 6.0 and later.
See Also
Declared In
AVAudioSession.houtputDataSources
An array of AVAudioSessionDataSourceDescription objects represeting the available output data sources for the audio session. (read-only)
Discussion
When there is an audio accessory that supports output data source selection, this property is populated with all of the available output data sources. This currently only applies to certain USB devices.
This property is also key-value observable so you can be informed when any changes are made to the array of output data sources.
Availability
- Available in iOS 6.0 and later.
Declared In
AVAudioSession.houtputLatency
The latency for audio output, measured in seconds. (read-only)
Availability
- Available in iOS 6.0 and later.
Declared In
AVAudioSession.houtputNumberOfChannels
The number of audio output channels. (read-only)
Availability
- Available in iOS 6.0 and later.
Declared In
AVAudioSession.houtputVolume
The current output volume for your app’s audio content. (read-only)
Discussion
This value is in the range 0.0 to 1.0, with 0.0 representing no sound output and 1.0 representing the maximum volume.
You can observe changes to the value of this property using key-value observing.
Availability
- Available in iOS 6.0 and later.
Declared In
AVAudioSession.hpreferredIOBufferDuration
The preferred I/O buffer duration, in seconds. (read-only)
Availability
- Available in iOS 3.0 and later.
Declared In
AVAudioSession.hpreferredSampleRate
The preferred sample rate, in hertz (read-only)
Availability
- Available in iOS 6.0 and later.
Declared In
AVAudioSession.hsampleRate
The audio sample rate (in hertz) that is currently in effect. (read-only)
Availability
- Available in iOS 6.0 and later.
Declared In
AVAudioSession.hClass Methods
sharedInstance
Returns the singleton audio session.
Availability
- Available in iOS 3.0 and later.
Declared In
AVAudioSession.hInstance Methods
overrideOutputAudioPort:error:
Changes the current output route for audio.
Parameters
- portOverride
The override option for output. For a list of constants, see
“AVAudioSessionPortOverride”.- outError
On input, specify a pointer to an error object. If an error occurs, the pointer is set to an
NSErrorobject that describes the error. If you do not want error information, pass innil.
Return Value
YES if the new routing option was set successfully or NO if it was not.
Discussion
You can use this method to route audio temporarily away from the current outputs and to a different destination. Similarly, you can use this method to remove any overrides and return to the original outputs. Currently, you can use this method to reroute audio to the device’s built-in speaker.
Availability
- Available in iOS 6.0 and later.
Declared In
AVAudioSession.hsetActive:error:
Activates or deactivates your app’s audio session.
Parameters
- beActive
Use
YESto activate your app’s audio session orNOto deactivate it.- outError
On input, specify a pointer to an error object. If an error occurs, the pointer is set to an
NSErrorobject that describes the error. If you do not want error information, pass innil.
Return Value
Returns YES on success or NO on failure.
Discussion
If another app’s active audio session has higher priority than your app, and that other audio session does not allow mixing with other apps, attempting to activate your audio session may fail.
Availability
- Available in iOS 3.0 and later.
Declared In
AVAudioSession.hsetActive:withOptions:error:
Activates or deactivates your app’s audio session using the specified options.
Parameters
- active
Specify
YESto activate your app’s audio session orNOto deactivate it.- options
A bitmapped value containing one or more constants from the “AVAudioSessionSetActiveOptions” enumeration.
- outError
On input, specify a pointer to an error object. If an error occurs, the pointer is set to an
NSErrorobject that describes the error. If you do not want error information, pass innil.
Return Value
YES if the session’s active state was changed successfully or NO if it was not.
Discussion
If another app’s active audio session has higher priority than your app, and that other audio session does not allow mixing with other apps, attempting to activate your audio session may fail.
Availability
- Available in iOS 6.0 and later.
Declared In
AVAudioSession.hsetCategory:error:
Sets the audio session category.
Parameters
- theCategory
The audio session category you want to apply to the audio session. See “Audio Session Categories.”
- outError
On input, specify a pointer to an error object. If an error occurs, the pointer is set to an
NSErrorobject that describes the error. If you do not want error information, pass innil.
Return Value
Returns YES on success or NO on failure.
Availability
- Available in iOS 3.0 and later.
See Also
Declared In
AVAudioSession.hsetCategory:withOptions:error:
Sets the audio session category with the specified options.
Parameters
- category
The audio session category you want to apply to the audio session. For a list of values, see “Audio Session Categories.”
- options
The additional options for handling audio. For a list of constants, see “AVAudioSessionCategoryOptions”
- outError
On input, specify a pointer to an error object. If an error occurs, the pointer is set to an
NSErrorobject that describes the error. If you do not want error information, pass innil.
Return Value
YES if the category and options were set successfully or NO if they were not.
Availability
- Available in iOS 6.0 and later.
Declared In
AVAudioSession.hsetInputDataSource:error:
Sets the input data source for an audio session.
Parameters
- dataSource
The data source for the audio session’s input.
- outError
On input, specify a pointer to an error object. If an error occurs, the pointer is set to an
NSErrorobject that describes the error. If you do not want error information, pass inNULL.
Return Value
YES if the input data source for the audio session was successfully assigned; otherwise NO.
Discussion
The AVAudioSessionDataSourceDescription object that is passed in as the dataSource will be assigned to the inputDataSource property if this method was successful. Only objects from the inputDataSources property may be passed in for the dataSource parameter.
Availability
- Available in iOS 6.0 and later.
See Also
Declared In
AVAudioSession.hsetInputGain:error:
Changes the input gain to the specified value.
Parameters
- gain
The new gain value, which must be in the range
0.0to1.0, where0.0represents no additional gain and1.0represents the maximum possible gain.- outError
On input, specify a pointer to an error object. If an error occurs, the pointer is set to an
NSErrorobject that describes the error. If you do not want error information, pass innil.
Return Value
YES if the new gain value was set successfully or NO if it was not.
Discussion
Before calling this method, you should check the value in the inputGainSettable property to make sure the input gain level is settable for the current inputs.
Availability
- Available in iOS 6.0 and later.
Declared In
AVAudioSession.hsetMode:error:
Sets the audio session mode.
Parameters
- theMode
The audio session mode you want to apply to the audio session. See “Audio Session Modes.”
- outError
On input, specify a pointer to an error object. If an error occurs, the pointer is set to an
NSErrorobject that describes the error. If you do not want error information, pass innil.
Return Value
Returns YES on success or NO on failure.
Availability
- Available in iOS 5.0 and later.
Declared In
AVAudioSession.hsetOutputDataSource:error:
Sets the output data source for an audio session.
Parameters
- dataSource
The data source for the audio session’s output.
- outError
On input, specify a pointer to an error object. If an error occurs, the pointer is set to an
NSErrorobject that describes the error. If you do not want error information, pass inNULL.
Return Value
YES if the output data source for the audio session was successfully assigned; otherwise NO.
Discussion
The AVAudioSessionDataSourceDescription object that is passed in as the dataSource will be assigned to the outputDataSource property if this method was successful. Only objects from the outputDataSources property may be passed in for the dataSource parameter.
Availability
- Available in iOS 6.0 and later.
See Also
Declared In
AVAudioSession.hsetPreferredIOBufferDuration:error:
Sets the preferred audio I/O buffer duration, in seconds.
Parameters
- duration
The audio I/O buffer duration, in seconds, that you want to use. The available range for I/O buffer duration is 0.005 through 0.093 s, corresponding to a range of 256 through 4,096 sample frames at 44.1 kHz.
- outError
On input, specify a pointer to an error object. If an error occurs, the pointer is set to an
NSErrorobject that describes the error. If you do not want error information, pass innil.
Return Value
Returns YES on success or NO on failure.
Discussion
The audio I/O buffer duration is the number of seconds for a single audio input/output cycle. For example, with an I/O buffer duration of 0.005 s, on each audio I/O cycle:
You receive 0.005 s of audio if obtaining input.
You must provide 0.005 s of audio if providing output.
To obtain the actual I/O buffer duration, call the AudioSessionGetProperty function using the kAudioSessionProperty_CurrentHardwareIOBufferDuration key as its inID parameter.
For more information see “Querying and Using Audio Hardware Characteristics” in Audio Session Programming Guide.
Availability
- Available in iOS 3.0 and later.
See Also
Declared In
AVAudioSession.hsetPreferredSampleRate:error:
Sets the preferred sample rate for input and output.
Parameters
- sampleRate
The hardware sample rate you want to use. The available range for hardware sample rate is device dependent. It typically ranges from 8,000 through 48,000 hertz.
- outError
On input, specify a pointer to an error object. If an error occurs, the pointer is set to an
NSErrorobject that describes the error. If you do not want error information, pass innil.
Return Value
YES if the preferred sample rate was accepted and set or NO if it was not.
Discussion
The audio hardware input and output sample rates are always equal to each other when input and output are both running. For more information, see “Querying and Using Audio Hardware Characteristics” in Audio Session Programming Guide.
Availability
- Available in iOS 6.0 and later.
Declared In
AVAudioSession.hConstants
Audio Session Categories
Category identifiers for audio sessions, used as values for the setCategory:error: method.
NSString *const AVAudioSessionCategoryAmbient; NSString *const AVAudioSessionCategorySoloAmbient; NSString *const AVAudioSessionCategoryPlayback; NSString *const AVAudioSessionCategoryRecord; NSString *const AVAudioSessionCategoryPlayAndRecord; NSString *const AVAudioSessionCategoryAudioProcessing; NSString *const AVAudioSessionCategoryMultiRoute;
Constants
AVAudioSessionCategoryAmbientFor an app in which sound playback is nonprimary—that is, your app can be used successfully with the sound turned off.
This category is also appropriate for “play along” style apps, such as a virtual piano that a user plays over iPod audio. When you use this category, audio from other apps mixes with your audio. Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone).
Available in iOS 3.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionCategorySoloAmbientThe default category; used unless you set a category with the
setCategory:error:method.When you use this category, audio from other apps is silenced. Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone).
Available in iOS 3.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionCategoryPlaybackFor playing recorded music or other sounds that are central to the successful use of your app.
When using this category, your app audio continues with the Silent switch set to silent or when the screen locks. (The switch is called the Ring/Silent switch on iPhone.) To continue playing audio when your app transitions to the background (for example, when the screen locks), you need to add the
audiovalue to the “UIBackgroundModes” in Information Property List Key Reference key in your information property list file.This category normally prevents audio from other apps from mixing with your app's audio. To allow mixing for this category, use the
kAudioSessionProperty_OverrideCategoryMixWithOthersproperty.Available in iOS 3.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionCategoryRecordFor recording audio; this category silences playback audio. Recording continues with the screen locked.
Available in iOS 3.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionCategoryPlayAndRecordAllows recording (input) and playback (output) of audio, such as for a VOIP (voice over IP) app.
Your audio continues with the Silent switch set to silent and with the screen locked. (The switch is called the Ring/Silent switch on iPhone.) To continue playing audio when your app transitions to the background (for example, when the screen locks), you need to add the
audiovalue to the “UIBackgroundModes” in Information Property List Key Reference key in your information property list file.This category is appropriate for simultaneous recording and playback, and also for apps that record and play back but not simultaneously. If you want to ensure that sounds such as Messages alerts do not play while your app is recording, use the
AVAudioSessionCategoryRecordcategory instead.This category normally prevents audio from other apps from mixing with your app's audio. To allow mixing when using this category, use the
kAudioSessionProperty_OverrideCategoryMixWithOthersproperty.Available in iOS 3.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionCategoryAudioProcessingFor using an audio hardware codec or signal processor while not playing or recording audio. Use this category, for example, when performing offline audio format conversion.
This category disables playback (audio output) and disables recording (audio input).
Audio processing does not normally continue when your app is in the background. However, when your app moves to the background, you can request additional time to complete processing. For more information, see iOS App Programming Guide.
Available in iOS 3.1 and later.
Declared in
AVAudioSession.h.AVAudioSessionCategoryMultiRouteAllows you to output distinct streams of audio data to different output devices at the same time. For example, you would use this category to route audio to both a USB device and a set of headphones. Use of this category requires a more detailed knowledge of, and interaction with, the capabilities of the available audio routes.
This category may be used for input, output, or both.
Available in iOS 6.0 and later.
Declared in
AVAudioSession.h.
Discussion
Each app running in iOS has a single audio session, which in turn has a single category. You can change your audio session’s category while your app is running.
You can refine the configuration provided by the AVAudioSessionCategoryRecord and AVAudioSessionCategoryPlayAndRecord categories by using an audio session mode, as described in “Audio Session Modes.”
Use the AVAudioSessionCategoryAmbient category when you want your sounds to mix with other audio (such as from the iPod app). Use one of the other playback categories when you want audio from other apps to be silenced when your session is active. However, you can enable mixing for the AVAudioSessionCategoryPlayback and AVAudioSessionCategoryPlayAndRecord categories by using the kAudioSessionProperty_OverrideCategoryMixWithOthers property. For more information on audio session categories, see Audio Session Programming Guide.
AVAudioSessionCategoryOptions
Constants that specify optional audio behaviors.
typedef NS_OPTIONS(NSUInteger,
AVAudioSessionCategoryOptions)
{
AVAudioSessionCategoryOptionMixWithOthers = 1,
AVAudioSessionCategoryOptionDuckOthers = 2,
AVAudioSessionCategoryOptionAllowBluetooth = 4,
AVAudioSessionCategoryOptionDefaultToSpeaker = 8
};
Constants
AVAudioSessionCategoryOptionMixWithOthersAllow audio in this session to be mixed with audio from other active sessions. This option is only valid if the session category is
AVAudioSessionCategoryPlayAndRecordorAVAudioSessionCategoryPlayback.Available in iOS 6.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionCategoryOptionDuckOthersAllow audio in this session to duck under the audio for other active sessions. This option is only valid if the session category is
AVAudioSessionCategoryPlayAndRecord.Available in iOS 6.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionCategoryOptionAllowBluetoothAllow audio in this session to be received from or sent to a Bluetooth device. This option is only valid if the session category is
AVAudioSessionCategoryPlayAndRecordorAVAudioSessionCategoryRecord.Available in iOS 6.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionCategoryOptionDefaultToSpeakerAllow audio in this session to route to the built-in speaker by default. This option is only valid if the session category is
AVAudioSessionCategoryPlayAndRecord.Available in iOS 6.0 and later.
Declared in
AVAudioSession.h.
Audio Session Modes
Mode identifiers for audio sessions, used as values for the setMode:error: method.
NSString *const AVAudioSessionModeDefault; NSString *const AVAudioSessionModeVoiceChat; NSString *const AVAudioSessionModeGameChat NSString *const AVAudioSessionModeVideoRecording; NSString *const AVAudioSessionModeMeasurement; NSString *const AVAudioSessionModeMoviePlayback;
Constants
AVAudioSessionModeDefaultThe default mode; used unless you set a mode with the
setMode:error:method.When this mode is in use, audio session behavior matches that of iOS versions prior to iOS 5.0. You can use this mode with every audio session category. On devices more than one built-in microphone, the primary microphone is used.
Available in iOS 5.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionModeVoiceChatSpecify this mode if your app is performing two-way voice communication, such as using Voice over Internet Protocol (VoIP).
When this mode is in use, the device’s tonal equalization is optimized for voice. For use with the
AVAudioSessionCategoryPlayAndRecordaudio session category. On devices with more than one built-in microphone, the primary microphone is used.Using this mode has the side effect of setting the
kAudioSessionProperty_OverrideCategoryEnableBluetoothInputcategory override toTRUE.Available in iOS 5.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionModeGameChatDo not set this mode directly. This mode is set by Game Kit on behalf of an application that uses a
GKVoiceChatobject. This mode is valid only with theAVAudioSessionCategoryPlayAndRecordcategory.If you need similar behavior and are not using a
GKVoiceChatobject, useAVAudioSessionModeVoiceChatinstead.Available in iOS 5.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionModeVideoRecordingSpecify this mode if your app is recording a movie.
For use with the
AVAudioSessionCategoryRecordaudio session category. Also works with theAVAudioSessionCategoryPlayAndRecordcategory. On devices with more than one built-in microphone, the microphone closest to the video camera is used.Using this mode may result in the system providing appropriate audio signal processing.
Available in iOS 5.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionModeMeasurementSpecify this mode if your app is performing measurement of incoming audio.
When this mode is in use, the device does not perform automatic gain adjustment on incoming audio. For use with the
AVAudioSessionCategoryRecordorAVAudioSessionCategoryPlayAndRecordaudio session categories. On devices with more than one built-in microphone, the primary microphone is used.Available in iOS 5.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionModeMoviePlaybackSpecify this mode if your app is playing back movie content.
When this mode is in use, the device engages any appropriate signal processing hardware to improve audio content played over the built-in speaker.
Available in iOS 6.0 and later.
Declared in
AVAudioSession.h.
Discussion
Each app running in iOS has a single audio session, which in turn has a single mode. A mode refines the device’s audio configuration according to the purpose of the mode. You can change your audio session’s mode only when your audio session is inactive, and only if your audio session category is configured to disallow mixing with other apps.
AVAudioSessionInterruptionOptions
Constant that indicates the state of the audio session following an interruption
typedef NS_OPTIONS(NSUInteger,
AVAudioSessionInterruptionOptions)
{
AVAudioSessionInterruptionOptionShouldResume = 1
};
Constants
AVAudioSessionInterruptionOptionShouldResumeIndicates that the audio session is active and immediately ready to be used. Your app can resume the audio operation that was interrupted.
Look for this flag in the flags parameter when your audio session delegate’s
endInterruptionWithFlags:method is invoked.Available in iOS 6.0 and later.
Declared in
AVAudioSession.h.
AVAudioSessionSetActiveOptions
A flag that provides additional information about your app’s audio intentions upon session activation or deactivation.
typedef NS_OPTIONS(NSUInteger,
AVAudioSessionSetActiveOptions)
{
AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation = 1
};
Constants
AVAudioSessionSetActiveOptionNotifyOthersOnDeactivationWhen passed in the flags parameter of the
setActive:withFlags:error:instance method, indicates that when your audio session deactivates, other audio sessions that had been interrupted by your session can return to their active state.This flag is used only when deactivating your audio session; that is, when you pass a value of
NOin the beActive parameter of thesetActive:withFlags:error:instance method.Available in iOS 6.0 and later.
Declared in
AVAudioSession.h.
AVAudioSessionPortOverride
Constants to use when overriding the output audio port.
typedef NS_ENUM(NSUInteger,
AVAudioSessionPortOverride)
{
AVAudioSessionPortOverrideNone = 0,
AVAudioSessionPortOverrideSpeaker = 'spkr'
};
Constants
AVAudioSessionPortOverrideNoneDo not override the output audio port. Use this option to route audio to the intended outputs.
Available in iOS 6.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionPortOverrideSpeakerOverride the current outputs and route audio to the built-in speaker. Use this override only in conjunction with the
AVAudioSessionCategoryPlayAndRecordcategory.Available in iOS 6.0 and later.
Declared in
AVAudioSession.h.
AVAudioSessionRouteChangeReason
Constants indicating the reason for an audio route change.
typedef NS_ENUM(NSUInteger,
AVAudioSessionRouteChangeReason)
{
AVAudioSessionRouteChangeReasonUnknown = 0,
AVAudioSessionRouteChangeReasonNewDeviceAvailable = 1,
AVAudioSessionRouteChangeReasonOldDeviceUnavailable = 2,
AVAudioSessionRouteChangeReasonCategoryChange = 3,
AVAudioSessionRouteChangeReasonOverride = 4,
AVAudioSessionRouteChangeReasonWakeFromSleep = 6,
AVAudioSessionRouteChangeReasonNoSuitableRouteForCategory = 7
};
Constants
AVAudioSessionRouteChangeReasonUnknownThe reason for the change is unknown.
Available in iOS 6.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionRouteChangeReasonNewDeviceAvailableA preferred new audio output path is now available.
Available in iOS 6.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionRouteChangeReasonOldDeviceUnavailableThe previous audio output path is no longer available.
Available in iOS 6.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionRouteChangeReasonCategoryChangeThe category of the session object changed.
Available in iOS 6.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionRouteChangeReasonOverrideThe output route was overridden by the app.
Available in iOS 6.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionRouteChangeReasonWakeFromSleepThe route changed when the device woke up from sleep.
Available in iOS 6.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionRouteChangeReasonNoSuitableRouteForCategoryThe route changed because no suitable route is now available for the specified category.
Available in iOS 6.0 and later.
Declared in
AVAudioSession.h.
AVAudioSessionInterruptionType
Constants that describe the state of the audio interruption.
typedef NS_ENUM(NSUInteger,
AVAudioSessionInterruptionType)
{
AVAudioSessionInterruptionTypeBegan = 1,
AVAudioSessionInterruptionTypeEnded = 0,
};
Constants
AVAudioSessionInterruptionTypeBeganThe system interrupted the audio session.
Available in iOS 6.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionInterruptionTypeEndedThe interruption ended.
Available in iOS 6.0 and later.
Declared in
AVAudioSession.h.
Notification User Info Keys
Keys available in the user info dictionary of an interruption notification.
NSString *const AVAudioSessionInterruptionTypeKey; NSString *const AVAudioSessionInterruptionOptionKey; NSString *const AVAudioSessionRouteChangeReasonKey; NSString *const AVAudioSessionRouteChangePreviousRouteKey;
Constants
AVAudioSessionInterruptionTypeKeyThe value for this key is an
NSNumberobject containing an unsigned integer that identifies the type of interruption. For a list of possible values, see“AVAudioSessionInterruptionType”.Available in iOS 6.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionInterruptionOptionKeyThe value for this key is an
NSNumberobject containing an unsigned integer that identifies any options associated with the interruption. For a list of possible flags, see“AVAudioSessionInterruptionOptions”.Available in iOS 6.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionRouteChangeReasonKeyThe value for this key is an
NSNumberobject containing an unsigned integer that identifies the reason why the route changed. For a list of possible values, see“AVAudioSessionRouteChangeReason”.Available in iOS 6.0 and later.
Declared in
AVAudioSession.h.AVAudioSessionRouteChangePreviousRouteKeyThe value for this key is an
AVAudioSessionRouteDescriptionobject with the previous route information.Available in iOS 6.0 and later.
Declared in
AVAudioSession.h.
Interruption Flags
Constants that indicate the state of the audio session following an interruption. (Deprecated. Use the constants in “AVAudioSessionInterruptionOptions” instead.)
enum {
AVAudioSessionInterruptionFlags_ShouldResume = 1
};
Constants
AVAudioSessionInterruptionFlags_ShouldResumeIndicates that your audio session is active and immediately ready to be used. Your app can resume the audio operation that was interrupted. (Deprecated. Use
AVAudioSessionInterruptionOptionShouldResumeinstead.)Look for this flag in the flags parameter when your audio session delegate’s
endInterruptionWithFlags:method is invoked.Available in iOS 4.0 and later.
Declared in
AVAudioSession.h.
Activation Flags
Flags that provide additional information about your app’s audio intentions upon session activation or deactivation. (Deprecated. Use the constants in “AVAudioSessionSetActiveOptions” instead.)
enum {
AVAudioSessionSetActiveFlags_NotifyOthersOnDeactivation = 1
};
Constants
AVAudioSessionSetActiveFlags_NotifyOthersOnDeactivationWhen passed in the flags parameter of the
setActive:withFlags:error:instance method, indicates that when your audio session deactivates, other audio sessions that had been interrupted by your session can return to their active state. (Deprecated. UseAVAudioSessionSetActiveOptionNotifyOthersOnDeactivationinstead.)This flag is used only when deactivating your audio session; that is, when you pass a value of
NOin the beActive parameter of thesetActive:withFlags:error:instance method.Available in iOS 4.0 and later.
Declared in
AVAudioSession.h.
Notifications
AVAudioSessionDidBeginInterruptionNotification
This notification is posted on the main thread of your app. There is no userInfo dictionary.
AVAudioSessionDidEndInterruptionNotification
This notification is posted on the main thread of your app. There is no userInfo dictionary.
AVAudioSessionInputDidBecomeAvailableNotification
This notification is posted on the main thread of your app. There is no userInfo dictionary.
AVAudioSessionInputDidBecomeUnavailableNotification
This notification is posted on the main thread of your app. There is no userInfo dictionary.
AVAudioSessionInterruptionNotification
The userInfo dictionary of this notification contains the AVAudioSessionInterruptionTypeKey. If the interruption type is AVAudioSessionInterruptionTypeEnded, this dictionary also contains the AVAudioSessionInterruptionOptionKey key. This notification is posted on the main thread of your app.
Availability
- Available in iOS 6.0 and later.
Declared In
AVAudioSession.hAVAudioSessionRouteChangeNotification
The userInfo dictionary of this notification contains the AVAudioSessionRouteChangeReasonKey and AVAudioSessionRouteChangePreviousRouteKey keys, which provide information about the route change.
Availability
- Available in iOS 6.0 and later.
Declared In
AVAudioSession.hAVAudioSessionMediaServicesWereResetNotification
Use this notification as a cue to reinitialize any audio players and recorders used by your app, as well as reappply your AVAudioSession state. This notification is posted on the main thread of your app. There is no userInfo dictionary.
Availability
- Available in iOS 6.0 and later.
Declared In
AVAudioSession.h© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-12-13)