Audio Session Services

Overview

These functions apply only to iOS. They do not apply to macOS.

Overview

Audio Session Services lets you specify the intended audio behavior for your iOS app. For example, you can specify whether you intend for your app’s audio to silence other apps or to mix with their audio. You also use this API to specify your app’s behavior when it is interrupted, such as by a phone call. When the system knows your intentions, it configures the audio hardware in the device to satisfy those intentions, as possible.

Topics

Callbacks

typealias AudioSessionInterruptionListener

Invoked when an audio interruption in iOS begins or ends.

typealias AudioSessionPropertyListener

Invoked when an audio session property changes in iOS.

Data Types

typealias AudioSessionPropertyID

The data type for an audio session property identifier.

Constants

Audio Session Property Identifiers

Property identifiers used with Audio Session Services in iOS.

Audio Session Categories

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

Audio Session Modes

Mode identifiers for audio sessions, used as values for the kAudioSessionProperty_Mode property.

Audio Route Change Reasons

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

Audio Session Category Route Overrides

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

Audio Session Activation Flags

Flags that provide additional information about your app’s audio intentions upon session activation or deactivation.

typealias AudioSessionInterruptionType

Identifiers that serve as values for the kAudioSessionProperty_InterruptionType property to indicate the nature of an interruption that has just ended.

Audio Session Interruption States

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

Alternative Audio Route Change Reason Dictionary Key

An alternate key for obtaining information about the reason for an audio route change.

Deprecated Audio Session Categories

Deprecated category identifiers for audio sessions. Do not use for new development.

Result Codes

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

var kAudioSessionNoError: Int

No error has occurred.

var kAudioSessionNotInitialized: Int

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

var kAudioSessionAlreadyInitialized: Int

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

var kAudioSessionInitializationError: Int

There was an error during audio session initialization.

var kAudioSessionUnsupportedPropertyError: Int

The audio session property is not supported.

var kAudioSessionBadPropertySizeError: Int

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

var kAudioSessionNotActiveError: Int

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

var kAudioServicesNoHardwareError: Int

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

var kAudioSessionNoCategorySet: Int

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.

var kAudioSessionIncompatibleCategory: Int

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.

var kAudioSessionUnspecifiedError: Int

An unspecified audio session error has occurred. This typically results from the audio system being in an inconsistent state.