AVAudioSession Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
- 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
Events
| Name | Description |
|---|---|
| BeginInterruption | |
| CategoryChanged | |
| EndInterruption | |
| InputAvailabilityChanged | |
| InputChannelsChanged | |
| OutputChannelsChanged | |
| SampleRateChanged | |