Class: AVAudioSession
Overview
An instance of the AVAudioSession class, called an audio session, is a singleton object that you employ to set the audio context for your app. Use this class to:
Instance Attribute Summary (collapse)
-
- category
readonly
The audio session category.
-
- categoryOptions
readonly
The options associated with the current category.
-
- currentRoute
readonly
The current audio routing information.
-
- inputAvailable
readonly
A Boolean value indicating whether an audio input path is available.
-
- inputDataSource
readonly
The currently selected output data source.
-
- inputDataSources
readonly
An array of AVAudioSessionDataSourceDescription objects represeting the available input data sources for the audio session.
-
- inputGain
readonly
The gain applied to inputs associated with the session.
-
- inputGainSettable
readonly
A Boolean value indicating whether the input gain can be set.
-
- inputLatency
readonly
The latency for audio input, measured in seconds.
-
- inputNumberOfChannels
readonly
The number of audio input channels associated with the session.
-
- IOBufferDuration
readonly
The I/O buffer duration (in seconds) that is currently in effect.
-
- mode
readonly
The audio session mode.
-
- otherAudioPlaying
readonly
A Boolean value indicating whether another app is currently playing audio.
-
- outputDataSources
readonly
An array of AVAudioSessionDataSourceDescription objects represeting the available output data sources for the audio session.
-
- outputLatency
readonly
The latency for audio output, measured in seconds.
-
- outputNumberOfChannels
readonly
The number of audio output channels.
-
- outputVolume
readonly
The current output volume for your app’s audio content.
-
- preferredIOBufferDuration
readonly
The preferred I/O buffer duration, in seconds.
-
- preferredSampleRate
readonly
The preferred sample rate, in hertz (read-only).
-
- sampleRate
readonly
The audio sample rate (in hertz) that is currently in effect.
Class Method Summary (collapse)
-
+ sharedInstance
Returns the singleton audio session.
Instance Method Summary (collapse)
-
- overrideOutputAudioPort:error:
Changes the current output route for audio.
-
- setActive:error:
Activates or deactivates your app’s audio session.
-
- setActive:withOptions:error:
Activates or deactivates your app’s audio session using the specified options.
-
- setCategory:error:
Sets the audio session category.
-
- setCategory:withOptions:error:
Sets the audio session category with the specified options.
-
- setInputDataSource:error:
Sets the input data source for an audio session.
-
- setInputGain:error:
Changes the input gain to the specified value.
-
- setMode:error:
Sets the audio session mode.
-
- setOutputDataSource:error:
Sets the output data source for an audio session.
-
- setPreferredIOBufferDuration:error:
Sets the preferred audio I/O buffer duration, in seconds.
-
- setPreferredSampleRate:error:
Sets the preferred sample rate for input and output.
Methods inherited from NSObject
#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version
Constructor Details
This class inherits a constructor from NSObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class NSObject
Instance Attribute Details
- (String) category (readonly)
The audio session category. (read-only) An audio session category is a key that identifies a set of audio behaviors for your app. An audio session has one of the categories listed in “Audio Session Categories.” The default category is AVAudioSessionCategorySoloAmbient. For more information, see Audio Session Programming Guide.
- (AVAudioSessionCategoryOptions) categoryOptions (readonly)
The options associated with the current category. (read-only) Category options allow you to tweak your app’s audio behavior in small ways. For a list of options that may be specified in this property, see “AVAudioSessionCategoryOptions”.
- (AVAudioSessionRouteDescription) currentRoute (readonly)
The current audio routing information. (read-only) The current audio route contains information about the input and output ports involved in the session. You can use the object in this property to retrieve those ports and get information about them.
- (Boolean) inputAvailable (readonly)
A Boolean value indicating whether an audio input path is available. (read-only) Use this property at launch time to determine whether the current device supports audio input. To respond to a change in the availability of audio input, register for the AVAudioSessionInputDidBecomeAvailableNotification and AVAudioSessionInputDidBecomeUnavailableNotification notifications.This property contains the value YES if a path is available or NO if one is not.
- (AVAudioSessionDataSourceDescription) inputDataSource (readonly)
The currently selected output data source. (read-only) If there are no output data sources available, the value of this property will be nil. The value of this property must be an AVAudioSessionDataSourceDescription object from the outputDataSources property.
- (Array) inputDataSources (readonly)
An array of AVAudioSessionDataSourceDescription objects represeting the available input data sources for the audio session. (read-only) This property is populated with all of the available input data sources by the system. This property is also key-value observable so you can be informed when any changes are made to the array of input data sources.
- (Float) inputGain (readonly)
The gain applied to inputs associated with the session. (read-only) The value in this property is in the range 0.0 to 1.0, where 0.0 represents no additional gain and 1.0 represents the maximum possible gain. You can observe changes to the value of this property using key-value observing.
- (Boolean) inputGainSettable (readonly)
A Boolean value indicating whether the input gain can be set. (read-only) Some inputs may not provide the ability to set the input gain, so it is important to check this property before attempting to set the input gain.
- (NSTimeInterval) inputLatency (readonly)
The latency for audio input, measured in seconds. (read-only)
- (Integer) inputNumberOfChannels (readonly)
The number of audio input channels associated with the session. (read-only)
- (NSTimeInterval) IOBufferDuration (readonly)
The I/O buffer duration (in seconds) that is currently in effect. (read-only)
- (String) mode (readonly)
The audio session mode. (read-only) An audio session mode is a key that identifies a set of device audio configuration details, such as whether or not the device performs automatic gain adjustment on incoming audio. A mode refines the configuration provided by a category. An audio session has one of the modes listed in “Audio Session Modes.” The default mode is AVAudioSessionModeDefault.
- (Boolean) otherAudioPlaying (readonly)
A Boolean value indicating whether another app is currently playing audio. (read-only)
- (Array) outputDataSources (readonly)
An array of AVAudioSessionDataSourceDescription objects represeting the available output data sources for the audio session. (read-only) This property is populated with all of the available output data sources by the system. This property is also key-value observable so you can be informed when any changes are made to the array of output data sources.
- (NSTimeInterval) outputLatency (readonly)
The latency for audio output, measured in seconds. (read-only)
- (Integer) outputNumberOfChannels (readonly)
The number of audio output channels. (read-only)
- (Float) outputVolume (readonly)
The current output volume for your app’s audio content. (read-only) This value is in the range 0.0 to 1.0, with 0.0 representing no sound output and 1.0 representing the maximum volume. You can observe changes to the value of this property using key-value observing.
- (NSTimeInterval) preferredIOBufferDuration (readonly)
The preferred I/O buffer duration, in seconds. (read-only)
- (Float) preferredSampleRate (readonly)
The preferred sample rate, in hertz (read-only)
- (Float) sampleRate (readonly)
The audio sample rate (in hertz) that is currently in effect. (read-only)
Class Method Details
+ (Object) sharedInstance
Returns the singleton audio session.
Instance Method Details
- (Boolean) overrideOutputAudioPort(portOverride, error:outError)
Changes the current output route for audio. You can use this method to route audio temporarily away from the current outputs and to a different destination. Similarly, you can use this method to remove any overrides and return to the original outputs. Currently, you can use this method to reroute audio to the device’s built-in speaker.
- (Boolean) setActive(beActive, error:outError)
Activates or deactivates your app’s audio session. If another app’s active audio session has higher priority than your app, and that other audio session does not allow mixing with other apps, attempting to activate your audio session may fail.
- (Boolean) setActive(active, withOptions:options, error:outError)
Activates or deactivates your app’s audio session using the specified options. If another app’s active audio session has higher priority than your app, and that other audio session does not allow mixing with other apps, attempting to activate your audio session may fail.
- (Boolean) setCategory(theCategory, error:outError)
Sets the audio session category.
- (Boolean) setCategory(category, withOptions:options, error:outError)
Sets the audio session category with the specified options.
- (Boolean) setInputDataSource(dataSource, error:outError)
Sets the input data source for an audio session. The AVAudioSessionDataSourceDescription object that is passed in as the dataSource will be assigned to the inputDataSource property if this method was successful. Only objects from the inputDataSources property may be passed in for the dataSource parameter.
- (Boolean) setInputGain(gain, error:outError)
Changes the input gain to the specified value. Before calling this method, you should check the value in the inputGainSettable property to make sure the input gain level is settable for the current inputs.
- (Boolean) setMode(theMode, error:outError)
Sets the audio session mode.
- (Boolean) setOutputDataSource(dataSource, error:outError)
Sets the output data source for an audio session. The AVAudioSessionDataSourceDescription object that is passed in as the dataSource will be assigned to the outputDataSource property if this method was successful. Only objects from the outputDataSources property may be passed in for the dataSource parameter.
- (Boolean) setPreferredIOBufferDuration(duration, error:outError)
Sets the preferred audio I/O buffer duration, in seconds. The audio I/O buffer duration is the number of seconds for a single audio input/output cycle. For example, with an I/O buffer duration of 0.005 s, on each audio I/O cycle:You receive 0.005 s of audio if obtaining input.You must provide 0.005 s of audio if providing output.To obtain the actual I/O buffer duration, call the AudioSessionGetProperty function using the kAudioSessionProperty_CurrentHardwareIOBufferDuration key as its inID parameter.For more information see “Querying and Using Audio Hardware Characteristics” in Audio Session Programming Guide.
- (Boolean) setPreferredSampleRate(sampleRate, error:outError)
Sets the preferred sample rate for input and output. The audio hardware input and output sample rates are always equal to each other when input and output are both running. For more information, see “Querying and Using Audio Hardware Characteristics” in Audio Session Programming Guide.