Share via


AVAudioSession Class

Definition

Coordinates an audio playback or capture session.

[Foundation.Register("AVAudioSession", true)]
public class AVAudioSession : Foundation.NSObject
public static class AVAudioSession
[<Foundation.Register("AVAudioSession", true)>]
type AVAudioSession = class
    inherit NSObject
type AVAudioSession = class
Inheritance
AVAudioSession
Inheritance
AVAudioSession
Attributes

Remarks

Application developers should use the singleton object retrieved by SharedInstance().

Because the audio hardware of an iOS device is shared between all apps, audio settings can only be "preferred" (see SetPreferred* methods) and the application developer must account for use-cases where these preferences are overridden.

The interaction of an app with other apps and system services is determined by your audio category. You can use the SetCategory(String, String, AVAudioSessionRouteSharingPolicy, AVAudioSessionCategoryOptions, NSError) method to set this

You should also control the Mode (using SetMode(NSString, NSError) to describe how your application will use audio.

As is common in AV Foundation, many methods in AVAudioSession are asynchronous and properties may take some time to reflect their final status. Application developers should be familiar with asynchronous programming techniques.

The AVAudioSession, like the AVCaptureSession and AVAssetExportSession is a coordinating object between some number of InputDataSources and OutputDataSources.

You can register to a few notifications that are posted by the audio system, by using the convenience methods in AVAudioSession.Notifications.

void Setup ()
{
	AVAudioSession.SharedInstance ().Init ();
	NSError error;
	if (!AVAudioSession.SharedInstance ().SetCategory (AVAudioSessionCategory.Playback, out error)) {
		ReportError (error);
		return;
	}
	AVAudioSession.Notifications.ObserveInterruption (ToneInterruptionListener);

	if (!AVAudioSession.SharedInstance ().SetActive (true, out error)) {
		ReportError (error);
		return;
	}

	void ToneInterruptionListener (object sender, AVAudioSessionInterruptionEventArgs interruptArgs)
	{
		//
	}
}

Constructors

Name Description
AVAudioSession(NativeHandle)

A constructor used when creating managed representations of unmanaged objects. Called by the runtime.

AVAudioSession(NSObjectFlag)

Constructor to call on derived classes to skip initialization and merely allocate the object.

Properties

Name Description
AllowHapticsAndSystemSoundsDuringRecording
AvailableCategories

Gets an array that contains descriptions of the session categories that the device can provide.

AvailableInputs

Gets an array that contains AVAudioSessionPortDescriptions that list the available audio sources on the device.

AvailableInputsChangeNotification

Notification constant for AvailableInputsChange

AvailableModes

Gets an array that contains the available audio session modes.

Category

Weakly-typed audio classification of the app, used to balance its demands with other apps on the device.

CategoryAmbient
Obsolete.

Represents the value associated with the constant AVAudioSessionCategoryAmbient

CategoryAudioProcessing
Obsolete.

Developers should not use this deprecated property.

CategoryMultiRoute
Obsolete.

Represents the value associated with the constant AVAudioSessionCategoryMultiRoute

CategoryOptions

Options for the Category.

CategoryPlayAndRecord
Obsolete.

Represents the value associated with the constant AVAudioSessionCategoryPlayAndRecord

CategoryPlayback
Obsolete.

Represents the value associated with the constant AVAudioSessionCategoryPlayback

CategoryRecord
Obsolete.

Represents the value associated with the constant AVAudioSessionCategoryRecord

CategorySoloAmbient
Obsolete.

Represents the value associated with the constant AVAudioSessionCategorySoloAmbient

ClassHandle

The Objective-C class handle for this class.

CurrentHardwareInputNumberOfChannels

Application developers should not use this deprecated property. Use InputNumberOfChannels instead.

CurrentHardwareOutputNumberOfChannels

Application developers should not use this deprecated property. Use OutputNumberOfChannels instead.

CurrentHardwareSampleRate

Application developers should not use this deprecated property. Use SampleRate instead.

CurrentRoute

The active input-output route.

Delegate

An instance of the AVFoundation.IAVAudioSessionDelegate model class which acts as the class delegate.

InputAvailable

Whether any input route supports audio.

InputDataSource

The currently selected input AVAudioSessionDataSourceDescription.

InputDataSources

The data sources available for the current input port.

InputGain

Input gain as a floating point value from 0 to 1.

InputGainSettable

Determines whether input gain is available.

InputIsAvailable

Application developers should not use this deprecated. Use InputAvailable instead.

InputLatency

The input latency, in seconds.

InputNumberOfChannels

The number of channels for the current input route.

InputOrientation
InterruptionNotification

Notification constant for Interruption

IOBufferDuration

The duration of the current buffer, in seconds.

IsEchoCancelledInputAvailable
IsEchoCancelledInputEnabled
IsMicrophoneInjectionAvailable
IsOutputMuted
MaximumInputNumberOfChannels

The largest number of channels available for the current input route.

MaximumOutputNumberOfChannels

The largest number of channels available for the current output route.

MediaServicesWereLostNotification

Notification constant for MediaServicesWereLost

MediaServicesWereResetNotification

Notification constant for MediaServicesWereReset

MicrophoneInjectionCapabilitiesChangeNotification

Notification constant for MicrophoneInjectionCapabilitiesChange

Mode
ModeDefault
Obsolete.

Represents the value associated with the constant AVAudioSessionModeDefault

ModeGameChat
Obsolete.

Represents the value associated with the constant AVAudioSessionModeGameChat

ModeMeasurement
Obsolete.

Represents the value associated with the constant AVAudioSessionModeMeasurement

ModeMoviePlayback
Obsolete.

Represents the value associated with the constant AVAudioSessionModeMoviePlayback

ModeSpokenAudio
Obsolete.

Represents the value associated with the constant AVAudioSessionModeSpokenAudio.

ModeVideoChat
Obsolete.

Represents the value associated with the constant AVAudioSessionModeVideoChat

ModeVideoRecording
Obsolete.

Represents the value associated with the constant AVAudioSessionModeVideoRecording

ModeVoiceChat
Obsolete.

Represents the value associated with the constant AVAudioSessionModeVoiceChat

OrientationLeft

Represents the value associated with the constant AVAudioSessionOrientationLeft

OrientationRight

Represents the value associated with the constant AVAudioSessionOrientationRight

OtherAudioPlaying

Whether another application is currently playing back audio.

OutputDataSource

The currently selected output data source.

OutputDataSources

An array of AVAudioSessionDataSourceDescriptions that list the available sources of the current output route.

OutputLatency

The output latency, in seconds.

OutputMuteStateChangeNotification

Notification constant for OutputMuteStateChange

OutputNumberOfChannels

The current number of channels in the output route.

OutputVolume

The current volume.

PolarPatternStereo

Represents the value associated with the constant 'AVAudioSessionPolarPatternStereo'.

PortAirPlay

Represents the value associated with the constant AVAudioSessionPortAirPlay

PortAvb

Represents the value associated with the constant 'AVAudioSessionPortAVB'.

PortBluetoothA2DP

Represents the value associated with the constant AVAudioSessionPortBluetoothA2DP

PortBluetoothHfp

Represents the value associated with the constant AVAudioSessionPortBluetoothHFP

PortBluetoothLE

Represents the value associated with the constant AVAudioSessionPortBluetoothLE

PortBuiltInMic

Represents the value associated with the constant AVAudioSessionPortBuiltInMic

PortBuiltInReceiver

Represents the value associated with the constant AVAudioSessionPortBuiltInReceiver

PortBuiltInSpeaker

Represents the value associated with the constant AVAudioSessionPortBuiltInSpeaker

PortCarAudio

Represents the value associated with the constant AVAudioSessionPortCarAudio

PortContinuityMicrophone

Represents the value associated with the constant 'AVAudioSessionPortContinuityMicrophone'.

PortDisplayPort

Represents the value associated with the constant 'AVAudioSessionPortDisplayPort'.

PortFireWire

Represents the value associated with the constant 'AVAudioSessionPortFireWire'.

PortHdmi

Represents the value associated with the constant AVAudioSessionPortHDMI

PortHeadphones

Represents the value associated with the constant AVAudioSessionPortHeadphones

PortHeadsetMic

Represents the value associated with the constant AVAudioSessionPortHeadsetMic

PortLineIn

Represents the value associated with the constant AVAudioSessionPortLineIn

PortLineOut

Represents the value associated with the constant AVAudioSessionPortLineOut

PortPci

Represents the value associated with the constant 'AVAudioSessionPortPCI'.

PortThunderbolt

Represents the value associated with the constant 'AVAudioSessionPortThunderbolt'.

PortUsbAudio

Represents the value associated with the constant AVAudioSessionPortUSBAudio

PortVirtual

Represents the value associated with the constant 'AVAudioSessionPortVirtual'.

PreferredHardwareSampleRate

Your desired audio sample rate.

PreferredInput

The preferred input port for audio routing.

PreferredInputOrientation
PreferredIOBufferDuration

Your application desired buffer size in seconds.

PreferredMicrophoneInjectionMode
PreferredSampleRate

The app's preferred sample rate, in Hz.

PrefersEchoCancelledInput
PrefersInterruptionOnRouteDisconnect
PrefersNoInterruptionsFromSystemAlerts
PromptStyle
RecordPermission

Gets a value that describes the currently granted recording permission status.

RenderingCapabilitiesChangeNotification

Notification constant for RenderingCapabilitiesChange

RenderingMode
RenderingModeChangeNotification

Notification constant for RenderingModeChange

RouteChangeNotification

Notification constant for RouteChange

RouteSharingPolicy
SampleRate

The current hardware sample rate, in Hz.

SecondaryAudioShouldBeSilencedHint

Gets a Boolean value that tells whether another app is playing audio.

SilenceSecondaryAudioHintNotification

Notification constant for SilenceSecondaryAudioHint

SpatialPlaybackCapabilitiesChangedNotification

Notification constant for SpatialPlaybackCapabilitiesChanged

SupportedOutputChannelLayouts
SupportsMultichannelContent
UserIntentToUnmuteOutputNotification

Notification constant for UserIntentToUnmuteOutput

VoicePrompt
WeakDelegate

Methods

Name Description
Activate(AVAudioSessionActivationOptions, Action<Boolean,NSError>)
ActivateAsync(AVAudioSessionActivationOptions)
Dispose(Boolean)
GetPreferredInputNumberOfChannels()

Retrieves the preferred number of input channels.

GetPreferredOutputNumberOfChannels()

Retrieves the preferred number of output channels.

OverrideOutputAudioPort(AVAudioSessionPortOverride, NSError)

Requests to temporarily change the output audio port.

RequestRecordPermission(AVPermissionGranted)

Presents a standard UI to the app user, asking for permission to record.

SetActive(Boolean, AVAudioSessionSetActiveOptions, NSError)

Activates and deactivates the audio session for the application.

SetActive(Boolean, AVAudioSessionSetActiveOptions)

Activates and deactivates the audio session for the application.

SetActive(Boolean, NSError)

Activates or deactivates the audio session for the application.

SetActive(Boolean)

Activates or deactivates the audio session for the application.

SetAggregatedIOPreference(AVAudioSessionIOType, NSError)
SetAllowHapticsAndSystemSoundsDuringRecording(Boolean, NSError)
SetCategory(AVAudioSessionCategory, AVAudioSessionCategoryOptions, NSError)
SetCategory(AVAudioSessionCategory, AVAudioSessionCategoryOptions)

Requests a change to the Category.

SetCategory(AVAudioSessionCategory, AVAudioSessionMode, AVAudioSessionCategoryOptions, NSError)
SetCategory(AVAudioSessionCategory, AVAudioSessionMode, AVAudioSessionCategoryOptions)
SetCategory(AVAudioSessionCategory, AVAudioSessionMode, AVAudioSessionRouteSharingPolicy, AVAudioSessionCategoryOptions, NSError)
SetCategory(AVAudioSessionCategory, String, AVAudioSessionCategoryOptions, NSError)
SetCategory(AVAudioSessionCategory, String, AVAudioSessionCategoryOptions)
SetCategory(AVAudioSessionCategory, String, AVAudioSessionRouteSharingPolicy, AVAudioSessionCategoryOptions, NSError)
SetCategory(AVAudioSessionCategory)

Requests a change to the Category.

SetCategory(NSString, NSError)

Weakly typed; Requests a change to the Category.

SetCategory(NSString)

Weakly typed; Requests a change to the Category.

SetCategory(String, AVAudioSessionCategoryOptions, NSError)

Weakly typed; Requests a change to the Category.

SetCategory(String, String, AVAudioSessionCategoryOptions, NSError)
SetCategory(String, String, AVAudioSessionRouteSharingPolicy, AVAudioSessionCategoryOptions, NSError)
SetInputDataSource(AVAudioSessionDataSourceDescription, NSError)

Selects the specified dataSource.

SetInputGain(Single, NSError)

Requests a specific gain level.

SetMode(AVAudioSessionMode, NSError)
SetMode(NSString, NSError)

Requests a specific mode.

SetOutputDataSource(AVAudioSessionDataSourceDescription, NSError)

Selects the specific output dataSource.

SetOutputMuted(Boolean, NSError)
SetPreferredHardwareSampleRate(Double, NSError)

Application developers should not use this deprecated method. Instead use SetPreferredSampleRate(Double, NSError)

SetPreferredInput(AVAudioSessionPortDescription, NSError)

Sets the preferred input data source.

SetPreferredInputNumberOfChannels(IntPtr, NSError)
SetPreferredInputOrientation(AVAudioStereoOrientation, NSError)
SetPreferredIOBufferDuration(Double, NSError)

Sets the preferred duration, in seconds, of the IO buffer.

SetPreferredMicrophoneInjectionMode(AVAudioSessionMicrophoneInjectionMode, NSError)
SetPreferredOutputNumberOfChannels(IntPtr, NSError)
SetPreferredSampleRate(Double, NSError)

Sets the preferred sample rate, in Hz.

SetPrefersEchoCancelledInput(Boolean, NSError)
SetPrefersInterruptionOnRouteDisconnect(Boolean, NSError)
SetPrefersNoInterruptionsFromSystemAlerts(Boolean, NSError)
SetSupportsMultichannelContent(Boolean, NSError)
SharedInstance()

Factory method that returns the shared AVAudioSession object.

Events

Name Description
BeginInterruption
CategoryChanged
EndInterruption
InputAvailabilityChanged
InputChannelsChanged
OutputChannelsChanged
SampleRateChanged

Extension Methods

Name Description
PrepareRouteSelectionForPlayback(AVAudioSession, Action<Boolean,AVAudioSessionRouteSelection>)
PrepareRouteSelectionForPlaybackAsync(AVAudioSession)
BrowserAccessibilityDeleteTextAtCursor(NSObject, IntPtr)
BrowserAccessibilityInsertTextAtCursor(NSObject, String)
GetAccessibilityLineEndPositionFromCurrentSelection(NSObject)
GetAccessibilityLineRangeForPosition(NSObject, IntPtr)
GetAccessibilityLineStartPositionFromCurrentSelection(NSObject)
GetBrowserAccessibilityAttributedValue(NSObject, NSRange)
GetBrowserAccessibilityContainerType(NSObject)
GetBrowserAccessibilityCurrentStatus(NSObject)
GetBrowserAccessibilityHasDomFocus(NSObject)
GetBrowserAccessibilityIsRequired(NSObject)
GetBrowserAccessibilityPressedState(NSObject)
GetBrowserAccessibilityRoleDescription(NSObject)
GetBrowserAccessibilitySelectedTextRange(NSObject)
GetBrowserAccessibilitySortDirection(NSObject)
GetBrowserAccessibilityValue(NSObject, NSRange)
SetBrowserAccessibilityContainerType(NSObject, BEAccessibilityContainerType)
SetBrowserAccessibilityCurrentStatus(NSObject, String)
SetBrowserAccessibilityHasDomFocus(NSObject, Boolean)
SetBrowserAccessibilityIsRequired(NSObject, Boolean)
SetBrowserAccessibilityPressedState(NSObject, BEAccessibilityPressedState)
SetBrowserAccessibilityRoleDescription(NSObject, String)
SetBrowserAccessibilitySelectedTextRange(NSObject, NSRange)
SetBrowserAccessibilitySortDirection(NSObject, String)
ProvideImageData(NSObject, IntPtr, UIntPtr, UIntPtr, UIntPtr, UIntPtr, UIntPtr, NSObject)
ProvideImageToMTLTexture(NSObject, IMTLTexture, IMTLCommandBuffer, UIntPtr, UIntPtr, UIntPtr, UIntPtr, NSObject)
SetSharedObservers(NSObject, NSKeyValueSharedObserversSnapshot)
GetDebugDescription(INSObjectProtocol)
GetHandle(INativeObject)
GetNonNullHandle(INativeObject, String)
GetAccessibilityCustomRotors(NSObject)

Gets the array of UIAccessibilityCustomRotor objects appropriate for this object.

SetAccessibilityCustomRotors(NSObject, UIAccessibilityCustomRotor[])

Sets the array of UIAccessibilityCustomRotor objects appropriate for this object.

AccessibilityHitTest(NSObject, CGPoint, UIEvent)
GetAccessibilityNextTextNavigationElement(NSObject)
GetAccessibilityNextTextNavigationElementBlock(NSObject)
GetAccessibilityPreviousTextNavigationElement(NSObject)
GetAccessibilityPreviousTextNavigationElementBlock(NSObject)
SetAccessibilityNextTextNavigationElement(NSObject, NSObject)
SetAccessibilityNextTextNavigationElementBlock(NSObject, AXObjectReturnBlock)
SetAccessibilityPreviousTextNavigationElement(NSObject, NSObject)
SetAccessibilityPreviousTextNavigationElementBlock(NSObject, AXObjectReturnBlock)
GetAccessibilityTextInputResponder(NSObject)
GetAccessibilityTextInputResponderHandler(NSObject)
SetAccessibilityTextInputResponder(NSObject, IUITextInput)
SetAccessibilityTextInputResponderHandler(NSObject, UITextInputReturnHandler)

Applies to

See also