AVAudioSession Class

Definition

Coordinates an audio playback or capture session.

[Foundation.Register("AVAudioSession", true)]
[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.WatchOS, 3, 0, ObjCRuntime.PlatformArchitecture.All, null)]
public class AVAudioSession : Foundation.NSObject
type AVAudioSession = class
    inherit NSObject
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

AVAudioSession(IntPtr)

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

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.

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

Represents the value associated with the constant AVAudioSessionCategoryAmbient

CategoryAudioProcessing

Developers should not use this deprecated property.

CategoryMultiRoute

Represents the value associated with the constant AVAudioSessionCategoryMultiRoute

CategoryOptions

Options for the Category.

CategoryPlayAndRecord

Represents the value associated with the constant AVAudioSessionCategoryPlayAndRecord

CategoryPlayback

Represents the value associated with the constant AVAudioSessionCategoryPlayback

CategoryRecord

Represents the value associated with the constant AVAudioSessionCategoryRecord

CategorySoloAmbient

Represents the value associated with the constant AVAudioSessionCategorySoloAmbient

Class (Inherited from NSObject)
ClassHandle

The 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.

DebugDescription

A developer-meaningful description of this object.

(Inherited from NSObject)
Delegate

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

Description

Description of the object, the Objective-C version of ToString.

(Inherited from NSObject)
Handle

Handle (pointer) to the unmanaged object representation.

(Inherited from NSObject)
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.

InterruptionNotification

Notification constant for Interruption

IOBufferDuration

The duration of the current buffer, in seconds.

IsDirectBinding (Inherited from NSObject)
IsProxy (Inherited from NSObject)
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

Mode

Configuration modes for Audio, it provides finer control over the Category property.

ModeDefault

Represents the value associated with the constant AVAudioSessionModeDefault

ModeGameChat

Represents the value associated with the constant AVAudioSessionModeGameChat

ModeMeasurement

Represents the value associated with the constant AVAudioSessionModeMeasurement

ModeMoviePlayback

Represents the value associated with the constant AVAudioSessionModeMoviePlayback

ModeSpokenAudio

Represents the value associated with the constant AVAudioSessionModeSpokenAudio.

ModeVideoChat

Represents the value associated with the constant AVAudioSessionModeVideoChat

ModeVideoRecording

Represents the value associated with the constant AVAudioSessionModeVideoRecording

ModeVoiceChat

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.

OutputNumberOfChannels

The current number of channels in the output route.

OutputVolume

The current volume.

PortAirPlay

Represents the value associated with the constant AVAudioSessionPortAirPlay

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

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

PortUsbAudio

Represents the value associated with the constant AVAudioSessionPortUSBAudio

PreferredHardwareSampleRate

Your desired audio sample rate.

PreferredInput

The preferred input port for audio routing.

PreferredIOBufferDuration

Your application desired buffer size in seconds.

PreferredSampleRate

The app's preferred sample rate, in Hz.

PromptStyle
RecordPermission

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

RetainCount

Returns the current Objective-C retain count for the object.

(Inherited from NSObject)
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.

Self (Inherited from NSObject)
SilenceSecondaryAudioHintNotification

Notification constant for SilenceSecondaryAudioHint

Superclass (Inherited from NSObject)
SuperHandle

Handle used to represent the methods in the base class for this NSObject.

(Inherited from NSObject)
VoicePrompt
WeakDelegate

An object that can respond to the delegate protocol for this type

Zone (Inherited from NSObject)

Methods

AddObserver(NSObject, NSString, NSKeyValueObservingOptions, IntPtr)

Registers an object for being observed externally (using NSString keyPath).   Observed changes are dispatched to the observer’s object ObserveValue(NSString, NSObject, NSDictionary, IntPtr) method.

(Inherited from NSObject)
AddObserver(NSObject, String, NSKeyValueObservingOptions, IntPtr)

Registers an object for being observed externally (using string keyPath).   Observed changes are dispatched to the observer’s object ObserveValue(NSString, NSObject, NSDictionary, IntPtr) method.

(Inherited from NSObject)
AddObserver(NSString, NSKeyValueObservingOptions, Action<NSObservedChange>)

Registers an object for being observed externally using an arbitrary method.

(Inherited from NSObject)
AddObserver(String, NSKeyValueObservingOptions, Action<NSObservedChange>)

Registers an object for being observed externally using an arbitrary method.

(Inherited from NSObject)
AwakeFromNib()

Called after the object has been loaded from the nib file. Overriders must call base.AwakeFromNib().

(Inherited from NSObject)
BeginInvokeOnMainThread(Action) (Inherited from NSObject)
BeginInvokeOnMainThread(Selector, NSObject)

Invokes asynchrously the specified code on the main UI thread.

(Inherited from NSObject)
Bind(NSString, NSObject, String, NSDictionary) (Inherited from NSObject)
Bind(String, NSObject, String, NSDictionary) (Inherited from NSObject)
BindingInfo(String) (Inherited from NSObject)
BindingOptionDescriptions(String) (Inherited from NSObject)
BindingValueClass(String) (Inherited from NSObject)
CommitEditing() (Inherited from NSObject)
CommitEditing(NSObject, Selector, IntPtr) (Inherited from NSObject)
ConformsToProtocol(IntPtr)

Invoked to determine if this object implements the specified protocol.

(Inherited from NSObject)
Copy()

Performs a copy of the underlying Objective-C object.

(Inherited from NSObject)
DangerousAutorelease() (Inherited from NSObject)
DangerousRelease() (Inherited from NSObject)
DangerousRetain() (Inherited from NSObject)
DidChange(NSKeyValueChange, NSIndexSet, NSString)

Indicates a change occurred to the indexes for a to-many relationship.

(Inherited from NSObject)
DidChange(NSString, NSKeyValueSetMutationKind, NSSet) (Inherited from NSObject)
DidChangeValue(String)

Indicates that a change occurred on the specified key.

(Inherited from NSObject)
Dispose()

Releases the resources used by the NSObject object.

(Inherited from NSObject)
Dispose(Boolean)

Releases the resources used by the AVAudioSession object.

DoesNotRecognizeSelector(Selector)

Indicates that this object does not recognize the specified selector.

(Inherited from NSObject)
Equals(NSObject) (Inherited from NSObject)
Equals(Object) (Inherited from NSObject)
ExposedBindings() (Inherited from NSObject)
GetBindingInfo(NSString) (Inherited from NSObject)
GetBindingOptionDescriptions(NSString) (Inherited from NSObject)
GetBindingValueClass(NSString) (Inherited from NSObject)
GetDictionaryOfValuesFromKeys(NSString[])

Retrieves the values of the specified keys.

(Inherited from NSObject)
GetHashCode()

Generates a hash code for the current instance.

(Inherited from NSObject)
GetMethodForSelector(Selector) (Inherited from NSObject)
GetNativeField(String) (Inherited from NSObject)
GetNativeHash() (Inherited from NSObject)
GetPreferredInputNumberOfChannels()

Retrieves the preferred number of input channels.

GetPreferredOutputNumberOfChannels()

Retrieves the preferred number of output channels.

Init() (Inherited from NSObject)
InitializeHandle(IntPtr) (Inherited from NSObject)
InitializeHandle(IntPtr, String) (Inherited from NSObject)
Invoke(Action, Double) (Inherited from NSObject)
Invoke(Action, TimeSpan) (Inherited from NSObject)
InvokeOnMainThread(Action) (Inherited from NSObject)
InvokeOnMainThread(Selector, NSObject)

Invokes synchrously the specified code on the main UI thread.

(Inherited from NSObject)
IsEqual(NSObject) (Inherited from NSObject)
IsKindOfClass(Class) (Inherited from NSObject)
IsMemberOfClass(Class) (Inherited from NSObject)
MarkDirty()

Promotes a regular peer object (IsDirectBinding is true) into a toggleref object.

(Inherited from NSObject)
MutableCopy()

Creates a mutable copy of the specified NSObject.

(Inherited from NSObject)
ObjectDidEndEditing(NSObject) (Inherited from NSObject)
ObserveValue(NSString, NSObject, NSDictionary, IntPtr)

Indicates that the value at the specified keyPath relative to this object has changed.

(Inherited from NSObject)
OverrideOutputAudioPort(AVAudioSessionPortOverride, NSError)

Requests to temporarily change the output audio port.

PerformSelector(Selector) (Inherited from NSObject)
PerformSelector(Selector, NSObject) (Inherited from NSObject)
PerformSelector(Selector, NSObject, Double)

Invokes the selector on the current instance and if the obj is not null, it passes this as its single parameter.

(Inherited from NSObject)
PerformSelector(Selector, NSObject, Double, NSString[]) (Inherited from NSObject)
PerformSelector(Selector, NSObject, NSObject) (Inherited from NSObject)
PerformSelector(Selector, NSThread, NSObject, Boolean) (Inherited from NSObject)
PerformSelector(Selector, NSThread, NSObject, Boolean, NSString[]) (Inherited from NSObject)
PrepareForInterfaceBuilder() (Inherited from NSObject)
RemoveObserver(NSObject, NSString)

Stops the specified observer from receiving further notifications of changed values for the specified keyPath.

(Inherited from NSObject)
RemoveObserver(NSObject, NSString, IntPtr)

Stops the specified observer from receiving further notifications of changed values for the specified keyPath and context.

(Inherited from NSObject)
RemoveObserver(NSObject, String)

Stops the specified observer from receiving further notifications of changed values for the specified keyPath.

(Inherited from NSObject)
RemoveObserver(NSObject, String, IntPtr)

Stops the specified observer from receiving further notifications of changed values for the specified keyPath and context.

(Inherited from NSObject)
RequestRecordPermission(AVPermissionGranted)

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

RespondsToSelector(Selector)

Whether this object recognizes the specified selector.

(Inherited from NSObject)
SetActive(Boolean)

Activates or deactivates the audio session for the application.

SetActive(Boolean, AVAudioSessionFlags, NSError)

Application developers should not use this deprecated method.

SetActive(Boolean, AVAudioSessionSetActiveOptions)

Activates and deactivates the audio session for the application.

SetActive(Boolean, AVAudioSessionSetActiveOptions, NSError)

Activates and deactivates the audio session for the application.

SetActive(Boolean, NSError)

Activates or deactivates the audio session for the application.

SetAggregatedIOPreference(AVAudioSessionIOType, NSError)
SetCategory(AVAudioSessionCategory)

Requests a change to the Category.

SetCategory(AVAudioSessionCategory, AVAudioSessionCategoryOptions)

Requests a change to the Category.

SetCategory(NSString)

Weakly typed; Requests a change to the Category.

SetCategory(NSString, NSError)

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(NSString, NSError)

Requests a specific mode.

SetNativeField(String, NSObject) (Inherited from NSObject)
SetNilValueForKey(NSString)

Sets the value of the specified key to null.

(Inherited from NSObject)
SetOutputDataSource(AVAudioSessionDataSourceDescription, NSError)

Selects the specific output dataSource.

SetPreferredHardwareSampleRate(Double, NSError)

M:AVFoundation.AVAudioSession.SetPreferredSampleRate(Double, out NSError)

SetPreferredInput(AVAudioSessionPortDescription, NSError)

Sets the preferred input data source.

SetPreferredInputNumberOfChannels(nint, NSError)
SetPreferredIOBufferDuration(Double, NSError)

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

SetPreferredOutputNumberOfChannels(nint, NSError)
SetPreferredSampleRate(Double, NSError)

Sets the preferred sample rate, in Hz.

SetValueForKey(NSObject, NSString)

Sets the value of the property specified by the key to the specified value.

(Inherited from NSObject)
SetValueForKeyPath(IntPtr, NSString)

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

(Inherited from NSObject)
SetValueForKeyPath(NSObject, NSString)

Sets the value of a property that can be reached using a keypath.

(Inherited from NSObject)
SetValueForUndefinedKey(NSObject, NSString)

Indicates an attempt to write a value to an undefined key. If not overridden, raises an NSUndefinedKeyException.

(Inherited from NSObject)
SetValuesForKeysWithDictionary(NSDictionary)

Sets the values of this NSObject to those in the specified dictionary.

(Inherited from NSObject)
SharedInstance()

Factory method that returns the shared AVAudioSession object.

ToString()

Returns a string representation of the value of the current instance.

(Inherited from NSObject)
Unbind(NSString) (Inherited from NSObject)
Unbind(String) (Inherited from NSObject)
ValueForKey(NSString)

Returns the value of the property associated with the specified key.

(Inherited from NSObject)
ValueForKeyPath(NSString)

Returns the value of a property that can be reached using a keypath.

(Inherited from NSObject)
ValueForUndefinedKey(NSString)

Indicates an attempt to read a value of an undefined key. If not overridden, raises an NSUndefinedKeyException.

(Inherited from NSObject)
WillChange(NSKeyValueChange, NSIndexSet, NSString)

Indicates that the values of the specified indices in the specified key are about to change.

(Inherited from NSObject)
WillChange(NSString, NSKeyValueSetMutationKind, NSSet) (Inherited from NSObject)
WillChangeValue(String)

Indicates that the value of the specified key is about to change.

(Inherited from NSObject)

Events

BeginInterruption

Developers should not use this deprecated method. Instead, they should use ObserveInterruption(NSObject, EventHandler<AVAudioSessionInterruptionEventArgs>).

CategoryChanged

An event indicating that the Category has changed.

EndInterruption

Developers should not use this deprecated method. Instead, they should use ObserveInterruption(NSObject, EventHandler<AVAudioSessionInterruptionEventArgs>).

InputAvailabilityChanged

Event indicating that the availability of inputs has changed.

InputChannelsChanged

Deprecated. This event is no longer raised.

OutputChannelsChanged

Deprecated. This event is no longer raised.

SampleRateChanged

An event indicating the SampleRate has changed.

Extension Methods

GetDebugDescription(INSObjectProtocol)
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.

Applies to

See also