iPhone OS Reference Library Apple Developer Connection spyglass button

Audio Session Services Reference

Framework
AudioToolbox/AudioToolbox.h
Declared in
AudioServices.h

Overview

This document describes Audio Session Services, a C interface for managing an application’s audio behavior in the context of other applications.

Audio Session Services lets you specify the intended audio behavior for your iPhone OS application. For example, you can specify whether you intend for your application’s audio to silence built-in applications or to mix with their audio. You also use Audio Session Services to specify your application’s behavior when it is interrupted, such as by a phone call.

Note: The information in this document was previously published as part of System Audio Services Reference.

Functions by Task

These functions apply only to iPhone OS. They do not apply to Mac OS X.

Initializing and Activating an Audio Session

Using Audio Session Properties

Functions

AudioSessionAddPropertyListener

Adds a property listener callback function to your application’s audio session object.

OSStatus AudioSessionAddPropertyListener (
   AudioSessionPropertyID         inID,
   AudioSessionPropertyListener   inProc,
   void                           *inClientData
);
Parameters
inID

The identifier for the audio session property whose value changes you want to listen for.

inProc

The name of your property listener callback function.

inClientData

Data that you would like to be passed to your property listener callback.

Return Value

A result code. See “Result Codes.”

Discussion

When an audio session property value changes, and you have added a listener callback for that property, the audio session object invokes the callback.

You can add exactly one listener callback for a given inID-inClientData pair. In other words, you can add more than one property listener callback function for a given audio session property, provided you pass a unique inClientData parameter value each time you add a property listener.

Audio session properties are listed and described in “Audio Session Services Property Identifiers.”

Availability
See Also
Related Sample Code
Declared In
AudioServices.h

AudioSessionGetProperty

Gets the value of a specified audio session property.

OSStatus AudioSessionGetProperty (
   AudioSessionPropertyID    inID,
   UInt32                    *ioDataSize,
   void                      *outData
);
Parameters
inID

The identifier for the audio session property that you want to get the value of.

ioDataSize

On input, the memory size for the outData parameter. On output, the actual size of the property value.

outData

On output, the value of the specified audio session property.

Return Value

A result code. See “Result Codes.”

Discussion

Audio session properties are listed and described in “Audio Session Services Property Identifiers.”

Availability
See Also
Related Sample Code
Declared In
AudioServices.h

AudioSessionGetPropertySize

Gets the size of the value for a specified audio session property.

OSStatus AudioSessionGetPropertySize (
   AudioSessionPropertyID    inID,
   UInt32                    *outDataSize
);
Parameters
inID

The identifier for the audio session property whose value you want to get the size of.

outDataSize

On output, the size of the property value.

Return Value

A result code. See “Result Codes.”

Discussion

Audio session properties are listed and described in “Audio Session Services Property Identifiers.”

Availability
See Also
Declared In
AudioServices.h

AudioSessionInitialize

Initializes an iPhone OS application’s audio session object.

OSStatus AudioSessionInitialize (
   CFRunLoopRef                      inRunLoop,
   CFStringRef                       inRunLoopMode,
   AudioSessionInterruptionListener  inInterruptionListener,
   void                              *inClientData
);
Parameters
inRunLoop

The run loop that the interruption listener callback should be run on. Pass NULL to use the main run loop.

inRunLoopMode

The mode for the run loop that the interruption listener function will run on. Passing NULL is equivalent to passing kCFRunLoopDefaultMode.

inInterruptionListener

The interruption listener callback function. The application’s audio session object invokes the callback when the session is interrupted and (if the application is still running) when the interruption ends. Can be NULL. See AudioSessionInterruptionListener.

inClientData

Data that you would like to be passed to your interruption listener callback.

Return Value

A result code. See “Result Codes.”

Discussion

Your application must call this function before making any other Audio Session Services calls. You may activate and deactivate your audio session as needed (see AudioSessionSetActive), but should initialize it only once.

Availability
Related Sample Code
Declared In
AudioServices.h

AudioSessionRemovePropertyListener

Removes an audio session property listener callback function. (Deprecated. Use AudioSessionRemovePropertyListenerWithUserData instead.)

OSStatus AudioSessionRemovePropertyListener (
   AudioSessionPropertyID  inID
);
Parameters
inID

The identifier for the audio session property whose value changes you no longer want to listen for.

Return Value

A result code. See “Result Codes.”

Availability
Declared In
AudioServices.h

AudioSessionRemovePropertyListenerWithUserData

Removes a property listener callback function from your application’s audio session object.

OSStatus AudioSessionRemovePropertyListenerWithUserData (
   AudioSessionPropertyID         inID,
   AudioSessionPropertyListener   inProc,
   void                           *inClientData
);
Parameters
inID

The identifier for the audio session property whose value changes you no longer want to listen for.

inProc

The name of your property listener callback function.

inClientData

The same custom data for the property listener callback that you passed when calling the AudioSessionAddPropertyListener function.

Return Value

A result code. See “Result Codes.”

Discussion

Audio session properties are listed and described in “Audio Session Services Property Identifiers.”

Availability
Declared In
AudioServices.h

AudioSessionSetActive

Actives or deactivates an audio session object.

OSStatus AudioSessionSetActive (
   Boolean    active
);
Parameters
active

Pass true to activate your application’s audio session, or false to deactivate it.

Return Value

A result code. See “Result Codes.”

Discussion

Activating your audio session may interrupt audio sessions belonging to built-in applications running in the background, depending on categories and priorities. Deactivating your audio session allows other, interrupted audio sessions to resume.

When another active audio session does not allow mixing, attempting to activate your audio session may fail.

Availability
Related Sample Code
Declared In
AudioServices.h

AudioSessionSetProperty

Sets the value of a specified audio session property.

OSStatus AudioSessionSetProperty (
   AudioSessionPropertyID    inID,
   UInt32                    inDataSize,
   const void                *inData
);
Parameters
inID

The identifier for the audio session property that you want to set the value of.

inDataSize

The size, in bytes, of the value in the inData parameter.

inData

The value that you are applying to the specified audio session property.

Return Value

A result code. See “Result Codes.”

Discussion

Audio session properties are listed and described in “Audio Session Services Property Identifiers.”

Availability
See Also
Related Sample Code
Declared In
AudioServices.h

Callbacks

AudioSessionInterruptionListener

Invoked when an audio interruption in iPhone OS begins or ends.

typedef void    (*AudioSessionInterruptionListener)(
   void     *inClientData,
   UInt32   inInterruptionState
   );

If you named your function MyInterruptionListener, you would declare it like this:

void MyInterruptionListener (
   void     *inClientData,
   UInt32   inInterruptionState
);

Parameters
inClientData

Data that you specified in the inClientData parameter of the AudioSessionInitialize function. Can be NULL.

inInterruptionState

A constant that indicates whether the interruption has just started or just ended. See “Audio Session Services Interruption States.”

Discussion

To register your interruption listener callback with your application’s audio session object, specify it in the AudioSessionInitialize function.

Availability
Declared In
AudioServices.h

AudioSessionPropertyListener

Invoked when an audio session property changes in iPhone OS.

typedef void    (*AudioSessionPropertyListener)(
   void                      *inClientData,
   AudioSessionPropertyID    inID,
   UInt32                    inDataSize,
   const void                *inData
   );

If you named your function MyPropertyListener, you would declare it like this:

void MyPropertyListener (
   void                      *inClientData,
   AudioSessionPropertyID    inID,
   UInt32                    inDataSize,
   const void                *inData
);

Parameters
inClientData

Data that you specified in the inClientData parameter of the AudioSessionAddPropertyListener function. Can be NULL.

inID

The identifier for the audio session property whose value just changed. See “Audio Session Services Property Identifiers.”

inDataSize

The size, in bytes, of the value of the changed property.

inData

The new value of the changed property.

Discussion

You can register one or more property listener callbacks with your application’s audio session object by calling the AudioSessionAddPropertyListener function.

Availability
Declared In
AudioServices.h

Data Types

AudioSessionPropertyID

The data type for an audio session property identifier.

typedef UInt32 AudioSessionPropertyID;
Discussion

Each Audio Session Services property has a four-character identifier. The properties are listed in “Audio Session Services Property Identifiers.”

Availability
Declared In
AudioServices.h

Constants

Audio Session Services Property Identifiers

Property identifiers used with Audio Session Services in iPhone OS.

enum {
   kAudioSessionProperty_PreferredHardwareSampleRate          = 'hwsr',
   // read/write
   kAudioSessionProperty_PreferredHardwareIOBufferDuration    = 'iobd',
   // read/write
   kAudioSessionProperty_AudioCategory                        = 'acat',
   // read/write
   kAudioSessionProperty_AudioRoute                           = 'rout',
   // read-only
   kAudioSessionProperty_AudioRouteChange                     = 'roch',
   // callback function
   kAudioSessionProperty_CurrentHardwareSampleRate            = 'chsr',
   // read-only
   kAudioSessionProperty_CurrentHardwareInputNumberChannels   = 'chic',
   // read-only
   kAudioSessionProperty_CurrentHardwareOutputNumberChannels  = 'choc',
   // read-only
   kAudioSessionProperty_CurrentHardwareOutputVolume          = 'chov',
   // read-only + callback function
   kAudioSessionProperty_CurrentHardwareInputLatency          = 'cilt',
   // read-only
   kAudioSessionProperty_CurrentHardwareOutputLatency         = 'colt',
   // read-only
   kAudioSessionProperty_CurrentHardwareIOBufferDuration      = 'chbd',
   // read-only
   kAudioSessionProperty_OtherAudioIsPlaying                  = 'othr',
   // read-only
   kAudioSessionProperty_OverrideAudioRoute                   = 'ovrd',
   // write-only
   kAudioSessionProperty_AudioInputAvailable                  = 'aiav',
   // read-only + callback function
   kAudioSessionProperty_ServerDied                           = 'died',
   // callback function
   kAudioSessionProperty_OtherMixableAudioShouldDuck          = 'duck',
   // read/write
   kAudioSessionProperty_OverrideCategoryMixWithOthers        = 'cmix',
   // read/write
   kAudioSessionProperty_OverrideCategoryDefaultToSpeaker     = 'cspk',
   // read/write
   kAudioSessionProperty_OverrideCategoryEnableBluetoothInput = 'cblu'
   // read/write
};
Constants
kAudioSessionProperty_PreferredHardwareSampleRate

Your preferred hardware sample rate for the audio session. A read/write Float64 value. The actual sample rate may be different and can be obtained using the kAudioSessionProperty_CurrentHardwareSampleRate property.

Available in iPhone OS 2.0 and later.

Declared in AudioServices.h.

kAudioSessionProperty_PreferredHardwareIOBufferDuration

Your preferred hardware IO buffer duration in seconds. A read/write Float32 value. The actual IO buffer duration may be different.

Available in iPhone OS 2.0 and later.

Declared in AudioServices.h.

kAudioSessionProperty_AudioCategory

The category for the audio session. A read/write UInt32 value. See “Audio Session Categories.”

Available in iPhone OS 2.0 and later.

Declared in AudioServices.h.

kAudioSessionProperty_AudioRoute

The name of the current audio route (such as “Headphone,” “Speaker,” and so on). A read-only CFStringRef value.

Available in iPhone OS 2.0 and later.

Declared in AudioServices.h.

kAudioSessionProperty_AudioRouteChange

A CFDictionaryRef object containing the reason the audio route changed and the name of the old route.

This object is available to your application only by way of a property listener callback function. See AudioSessionAddPropertyListener. The CFDictionary object contains two keys and values. The kAudioSession_AudioRouteChangeKey_Reason key has a CFNumberRef value that identifies the reason for the route change. See “Audio Session Route Change Reasons.” The kAudioSession_AudioRouteChangeKey_OldRoute key has a CFStringRef value that names the old audio route.

Available in iPhone OS 2.0 and later.

Declared in AudioServices.h.

kAudioSessionProperty_CurrentHardwareSampleRate

Indicates the current hardware sample rate. A read-only Float64 value.

Available in iPhone OS 2.0 and later.

Declared in AudioServices.h.

kAudioSessionProperty_CurrentHardwareInputNumberChannels

Indicates the current number of audio hardware input channels. A read-only UInt32 value.

Available in iPhone OS 2.0 and later.

Declared in AudioServices.h.

kAudioSessionProperty_CurrentHardwareOutputNumberChannels

Indicates the current number of audio hardware output channels. A read-only UInt32 value.

Available in iPhone OS 2.0 and later.

Declared in AudioServices.h.

kAudioSessionProperty_CurrentHardwareOutputVolume

Indicates the current audio output volume as Float32 value between 0.0 and 1.0. Read-only. This value is available to your application by way of a property listener callback function. See AudioSessionAddPropertyListener.

Available in iPhone OS 2.1 and later.

Declared in AudioServices.h.

kAudioSessionProperty_CurrentHardwareInputLatency

Indicates the current hardware input latency, in seconds, as a read-only Float32 value.

Available in iPhone OS 2.1 and later.

Declared in AudioServices.h.

kAudioSessionProperty_CurrentHardwareOutputLatency

Indicates the current hardware output latency, in seconds, as a read-only Float32 value.

Available in iPhone OS 2.1 and later.

Declared in AudioServices.h.

kAudioSessionProperty_CurrentHardwareIOBufferDuration

Indicates the current hardware IO buffer duration, in seconds, as a read-only Float32 value.

Available in iPhone OS 2.1 and later.

Declared in AudioServices.h.

kAudioSessionProperty_OtherAudioIsPlaying

Indicates whether or not another application (typically, the iPod application) is currently playing audio. Read-only. A non-zero UInt32 value indicates that other audio is playing.

Available in iPhone OS 2.1 and later.

Declared in AudioServices.h.

kAudioSessionProperty_OverrideAudioRoute

Specifies whether or not to override the audio session category’s normal audio route. Can be set with one of two values: kAudioSessionOverrideAudioRoute_None, which specifies that you want to use the normal audio route; and kAudioSessionOverrideAudioRoute_Speaker, when sends output audio to the speaker. A write-only UInt32 value.

Upon an audio route change (such as by plugging in or unplugging a headset), or upon interruption, this property reverts to its default value. This property can be used only with the kAudioSessionCategory_PlayAndRecord (or the equivalent AVAudioSessionCategoryRecord) category.

See also kAudioSessionProperty_OverrideCategoryDefaultToSpeaker.

Available in iPhone OS 2.1 and later.

Declared in AudioServices.h.

kAudioSessionProperty_AudioInputAvailable

Indicates if audio input is available (a nonzero value) or not (a value of 0). A read-only UInt32 value, interpreted as a Boolean value. Use this property, rather than the device model, to determine if audio input is available.

You can listen for changes in the value of this property using a callback function. For instance, if a user plugs a headset into an iPod touch (2nd generation), audio input becomes available via the wired microphone and your callback is invoked. See AudioSessionAddPropertyListener.

Available in iPhone OS 2.2 and later.

Declared in AudioServices.h.

kAudioSessionProperty_ServerDied

Indicates if the audio server has died (indicated by a nonzero UInt32 value) or is still running (a value of 0).

This value is available to your application only by way of a property listener callback function. See AudioSessionAddPropertyListener.

Available in iPhone OS 3.0 and later.

Declared in AudioServices.h.

kAudioSessionProperty_OtherMixableAudioShouldDuck

For audio session categories that allow mixing of iPod audio with application audio, specifies whether iPod audio should be reduced in level when your application produces sound. This property has a value of FALSE (0) by default. Set it to a nonzero value to turn on ducking.

Available in iPhone OS 3.0 and later.

Declared in AudioServices.h.

kAudioSessionProperty_OverrideCategoryMixWithOthers

Changes the mixing behavior of the kAudioSessionCategory_MediaPlayback and kAudioSessionCategory_PlayAndRecord audio session categories. Setting this property to TRUE (any nonzero value) allows mixing of iPod audio with application audio. Other aspects of these categories, such as their Ring/Silent switch behavior, are not affected.

This property has value of FALSE (0) by default. When the audio session category changes, such as during an interruption, the value of this property reverts to FALSE. To regain mixing behavior you must then re-set this property.

Always check to see if setting this property succeeds or fails, and react appropriately; behavior may change in future releases of iPhone OS.

Available in iPhone OS 3.0 and later.

Declared in AudioServices.h.

kAudioSessionProperty_OverrideCategoryDefaultToSpeaker

Specifies whether or not to route audio to the speaker (instead of to the receiver) when no other audio route, such as a headset, is connected. By default, the value of this property is FALSE (0). A read/write UInt32 value.

This property retains its value through an audio route change (such as when plugging in or unplugging a headset), and upon interruption; it reverts to its default value only upon an audio session category change. This property can be used only with the kAudioSessionCategory_PlayAndRecord (or the equivalent AVAudioSessionCategoryRecord) category.

See also kAudioSessionProperty_OverrideAudioRoute.

Available in iPhone OS 3.1 and later.

Declared in AudioServices.h.

kAudioSessionProperty_OverrideCategoryEnableBluetoothInput

Allows a paired Bluetooth device to appear as an available audio input route. By default, the value of this property is FALSE (0). A read/write UInt32 value.

This property can be used to modify the kAudioSessionCategory_RecordAudio or kAudioSessionCategory_PlayAndRecord categories.

Use of this property doesn’t affect the audio output route for the kAudioSessionCategory_PlayAndRecord category. Attempting to set this property to TRUE will fail for all categories other than kAudioSessionCategory_RecordAudio and kAudioSessionCategory_PlayAndRecord.

Available in iPhone OS 3.1 and later.

Declared in AudioServices.h.

Discussion

Use these property identifiers in concert with the AudioSessionGetProperty, AudioSessionSetProperty, and AudioSessionAddPropertyListener functions.

Audio Session Categories

Category identifiers for audio sessions, used as values for the kAudioSessionProperty_AudioCategory property.

enum {
   kAudioSessionCategory_UserInterfaceSoundEffects = 'uifx',  // deprecated
   kAudioSessionCategory_AmbientSound              = 'ambi',
   kAudioSessionCategory_SoloAmbientSound          = 'solo',
   kAudioSessionCategory_MediaPlayback             = 'medi',
   kAudioSessionCategory_LiveAudio                 = 'live',  // deprecated
   kAudioSessionCategory_RecordAudio               = 'reca',
   kAudioSessionCategory_PlayAndRecord             = 'plar'
   kAudioSessionCategory_AudioProcessing           = 'proc'
};
Constants
kAudioSessionCategory_UserInterfaceSoundEffects

For sound effects such as touch feedback, explosions, and so on.

Equivalent to the kAudioSessionCategory_AmbientSound category, which you should use instead. The kAudioSessionCategory_UserInterfaceSoundEffects category is deprecated in iPhone OS 3.0.

Available in iPhone OS 2.0 and later.

Declared in AudioServices.h.

kAudioSessionCategory_AmbientSound

For long-duration sounds such as rain, car engine noise, and so on. It is also for “play along” style applications, such a virtual piano that a user plays over iPod audio.

When you use this category, audio from built-in applications, such as the iPod, mixes with your audio. Your audio is silenced when the Ring/Silent switch is set to silent or when the screen locks.

Available in iPhone OS 2.0 and later.

Declared in AudioServices.h.

kAudioSessionCategory_SoloAmbientSound

The default category, used unless you set a category with the AudioSessionSetProperty function. The solo ambient sound category is for long-duration sounds such as rain, car engine noise, and so on.

When you use this category, audio from built-in applications, such as the iPod, is silenced. Your audio is silenced when the Ring/Silent switch is set to “silent” or when the screen locks.

Available in iPhone OS 2.2 and later.

Declared in AudioServices.h.

kAudioSessionCategory_MediaPlayback

For playing recorded music or other sounds that are central to the successful use of your application.

When using this category, your application audio continues with the Ring/Silent switch set to silent or when the screen locks.

This category normally disallows iPod audio to mix with application audio. To allow mixing for this category, use the kAudioSessionProperty_OverrideCategoryMixWithOthers property.

Available in iPhone OS 2.0 and later.

Declared in AudioServices.h.

kAudioSessionCategory_LiveAudio

For live performance of music, such as for an application that simulates a piano.

Equivalent to the kAudioSessionCategory_MediaPlayback category, which you should use instead. The kAudioSessionCategory_LiveAudio category is deprecated in iPhone OS 3.0.

Available in iPhone OS 2.0 and later.

Declared in AudioServices.h.

kAudioSessionCategory_RecordAudio

For recording audio; it silences playback audio.

Available in iPhone OS 2.0 and later.

Declared in AudioServices.h.

kAudioSessionCategory_PlayAndRecord

Allows recording (input) and playback (output) of audio, such as for a VOIP (voice over IP) application.

This category is appropriate for simultaneous recording and playback, and also for applications that record and play back but not simultaneously. If you want to ensure that sounds such as Messages alerts do not play while your application is recording, use the kAudioSessionCategory_RecordAudio category instead.

This category normally disallows iPod audio to mix with application audio. To allow mixing for this category, use the kAudioSessionProperty_OverrideCategoryMixWithOthers property.

Available in iPhone OS 2.0 and later.

Declared in AudioServices.h.

kAudioSessionCategory_AudioProcessing

For using an audio hardware codec or signal processor while not playing or recording audio.

Available in iPhone OS 3.1 and later.

Declared in AudioServices.h.

Discussion

Each application running in iPhone OS has a single audio session, which can be active or inactive. You can change your audio session’s category while your program is running.

The kAudioSessionCategory_AmbientSound category implies the intention that you want your sounds to mix with other sounds on the system—notably, with iPod audio. The categories further down in the list imply the intention that you want all other sounds to be silenced when your session is active. However, you can modify this behavior for the kAudioSessionCategory_MediaPlayback and kAudioSessionCategory_PlayAndRecord categories by using the kAudioSessionProperty_OverrideCategoryMixWithOthers property.

For more information on audio session categories, see Audio Session Programming Guide.

Audio Session Route Change Reasons

Identifiers for the various reasons that an audio route can change while your iPhone OS application is running.

enum {
   kAudioSessionRouteChangeReason_Unknown                    = 0,
   kAudioSessionRouteChangeReason_NewDeviceAvailable         = 1,
   kAudioSessionRouteChangeReason_OldDeviceUnavailable       = 2,
   kAudioSessionRouteChangeReason_CategoryChange             = 3,
   kAudioSessionRouteChangeReason_Override                   = 4,
   // this enum has no constant with a value of 5
   kAudioSessionRouteChangeReason_WakeFromSleep              = 6,
   kAudioSessionRouteChangeReason_NoSuitableRouteForCategory = 7
};
Constants
kAudioSessionRouteChangeReason_Unknown

The audio route changed but the reason is not known.

Available in iPhone OS 2.0 and later.

Declared in AudioServices.h.

kAudioSessionRouteChangeReason_NewDeviceAvailable

A new audio hardware device became available; for example, a headset was plugged in.

Available in iPhone OS 2.0 and later.

Declared in AudioServices.h.

kAudioSessionRouteChangeReason_OldDeviceUnavailable

The previously-used audio hardware device is now unavailable; for example, a headset was unplugged.

Available in iPhone OS 2.0 and later.

Declared in AudioServices.h.

kAudioSessionRouteChangeReason_CategoryChange

The audio session category has changed.

Available in iPhone OS 2.1 and later.

Declared in AudioServices.h.

kAudioSessionRouteChangeReason_Override

The audio route has been overridden. For example, while using the kAudioSessionCategory_PlayAndRecord category, output audio has been redirected to the speaker using the kAudioSessionProperty_OverrideAudioRoute property.

Available in iPhone OS 2.0 and later.

Declared in AudioServices.h.

kAudioSessionRouteChangeReason_WakeFromSleep

The iPhone or iPod touch woke from sleep.

Available in iPhone OS 2.0 and later.

Declared in AudioServices.h.

kAudioSessionRouteChangeReason_NoSuitableRouteForCategory

There is no audio hardware route for the audio session category; for instance, the kAudioSessionCategory_RecordAudio is set but there is no audio input device.

Available in iPhone OS 3.1 and later.

Declared in AudioServices.h.

Discussion

You encounter these identifiers as values in the CFDictionaryRef object passed to your property listener callback function when it is listening for audio route changes. See the description for kAudioSessionProperty_AudioRouteChange.

Audio Session Category Route Overrides

Specifies whether the default audio route for the PlayAndRecord category should be overridden.

enum {
   kAudioSessionOverrideAudioRoute_None    = 0,
   kAudioSessionOverrideAudioRoute_Speaker = 'spkr'
};
Constants
kAudioSessionOverrideAudioRoute_None

Specifies, for the kAudioSessionCategory_PlayAndRecord category, that output audio should go to the receiver. This is the default output audio route for this category.

Available in iPhone OS 2.1 and later.

Declared in AudioServices.h.

kAudioSessionOverrideAudioRoute_Speaker

Specifies, for the kAudioSessionCategory_PlayAndRecord category, that output audio should go to the speaker, not the receiver.

Available in iPhone OS 2.1 and later.

Declared in AudioServices.h.

Discussion

The kAudioSessionCategory_PlayAndRecord category supports simultaneous input and output. You could use this category, for example, to add an effect to audio coming into the iPhone’s microphone. By default, output audio for this category goes to the receiver—the speaker you hold to your ear when on a phone call. The kAudioSessionOverrideAudioRoute_Speaker constant lets you direct the output audio to the speaker situated at the bottom of the phone.

Audio Session Services Interruption States

Identifiers used with the AudioSessionInterruptionListener callback function in iPhone OS to indicate that an audio interruption has started or stopped.

enum {
   kAudioSessionBeginInterruption  = 1,
   kAudioSessionEndInterruption    = 0
};
Constants
kAudioSessionBeginInterruption

Your application’s audio session has just been interrupted, such as by a phone call.

Available in iPhone OS 2.0 and later.

Declared in AudioServices.h.

kAudioSessionEndInterruption

The interruption to your application’s audio session has just ended. In the case where a user confirms the interruption, such as answering a phone call, your application will not receive this constant.

Available in iPhone OS 2.0 and later.

Declared in AudioServices.h.

Audio Route Change Dictionary Keys

Keys for obtaining information about an audio hardware route change.

#define kAudioSession_AudioRouteChangeKey_Reason    "OutputDeviceDidChange_Reason"
#define kAudioSession_AudioRouteChangeKey_OldRoute  "OutputDeviceDidChange_OldRoute"
Constants
kAudioSession_AudioRouteChangeKey_Reason

The value for this key is a CFNumberRef object that identifies one of the reasons listed in “Audio Session Route Change Reasons.”

Available in iPhone OS 2.0 and later.

Declared in AudioServices.h.

kAudioSession_AudioRouteChangeKey_OldRoute

The value for this key is a CFStringRef object that names the previous audio hardware route (such as “Headphone” or “Speaker”).

Available in iPhone OS 2.0 and later.

Declared in AudioServices.h.

Discussion

Use these dictionary keys to obtain information, from the kAudioSessionProperty_AudioRouteChange property, about an audio hardware route change event.

Result Codes

This table lists the result codes defined for Audio Session Services.

Result CodeValueDescription
kAudioSessionNoError0

No error has occurred.

Available in iPhone OS 2.0 and later.

kAudioSessionNotInitialized '!ini'

An Audio Session Services function was called without first initializing the session. To avoid this error, call the AudioSessionInitialize function before attempting to use the session.

Available in iPhone OS 2.0 and later.

kAudioSessionAlreadyInitialized'init'

The AudioSessionInitialize function was called more than once during the lifetime of your application.

Available in iPhone OS 2.0 and later.

kAudioSessionInitializationError''ini?'

There was an error during audio session initialization.

Available in iPhone OS 2.0 and later.

kAudioSessionUnsupportedPropertyError'pty?'

The audio session property is not supported.

Available in iPhone OS 2.0 and later.

kAudioSessionBadPropertySizeError'!siz'

The size of the audio session property data was not correct.

Available in iPhone OS 2.0 and later.

kAudioSessionNotActiveError'!act'

The audio operation failed because your application’s audio session was not active.

Available in iPhone OS 2.0 and later.

kAudioServicesNoHardwareError'nohw'

The audio operation failed because the device has no audio input available.

Available in iPhone OS 3.0 and later.

kAudioSessionNoCategorySet'?cat'

The audio operation failed because it requires the audio session to have an explicitly-set category, but none was set. To use a hardware codec you must explicitly initialize the audio session and explicitly set an audio session category.

Available in iPhone OS 3.1 and later.

kAudioSessionIncompatibleCategory'!cat'

The specified audio session category cannot be used for the attempted audio operation. For example, you attempted to play or record audio with the audio session category set to kAudioSessionCategory_AudioProcessing.

Available in iPhone OS 3.1 and later.



Last updated: 2009-08-31

Did this document help you? Yes It's good, but... Not helpful...