In each iOS release, more audioSession properties are ported to AVFoundation, so you should use them as you see fit whenever it is available.
Since iOS 6 kAudioSessionProperty_OverrideAudioRoute is represented in the AVAudioSession method
- (BOOL)overrideOutputAudioPort:error:
Available Values: AVAudioSessionPortOverrideNone and AVAudioSessionPortOverrideSpeaker
Here is an example audio session that is fully configured with AVFoundation:
- (void)configureAVAudioSession { // Get your app audioSession singleton object AVAudioSession *session = [AVAudioSession sharedInstance]; // Error handling BOOL success; NSError *error; // set the audioSession category. // Needs to be Record or PlayAndRecord to use audioRouteOverride: success = [session setCategory:AVAudioSessionCategoryPlayAndRecord error:&error]; if (!success) { NSLog(@"AVAudioSession error setting category:%@",error); } // Set the audioSession override success = [session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&error]; if (!success) { NSLog(@"AVAudioSession error overrideOutputAudioPort:%@",error); } // Activate the audio session success = [session setActive:YES error:&error]; if (!success) { NSLog(@"AVAudioSession error activating: %@",error); } else { NSLog(@"AudioSession active"); } }
UPDATE
Starting with iOS 7.0, the audio session APIs are now completely deprecated in favor of AVAudioSession.
UPDATE 2
- (BOOL)overrideOutputAudioPort:error:
is a method, not a property, and it sets the base value of UInt32 for writing. You cannot get the current value, and you should consider the method as setting a temporary state. If the audio route changes or is interrupted, the property is reset to the default value ( AVAudioSessionPortOverrideNone ). You can receive interrupt notifications through AVAudioSessionDelegate .
foundry Sep 15 '13 at 1:41 2013-09-15 01:41
source share