Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVAudioSession output selection

If multiple input & output accessories are attached to iPhone, I want the user to be able to manually select the input & output source. I can manually select input by querying [[AVAudioSession sharedInstance] availableInputs] and then using setPreferredInput:error method in iOS 7, but I can not find anything similar for output. How do I achieve this ? I am using PlayAndRecord category.

like image 496
Deepak Sharma Avatar asked Feb 26 '26 05:02

Deepak Sharma


1 Answers

Apple don't want developers to change the output route/volume programmically. Maybe MPVolumeView is your choice.

Add a MPVolumeView, and then set its showsRouteButton to YES.

The Apple Documentation says, "The route button is visible by default when there is more than one audio output route available."

Like this: MPVolumeView example

Edit: Although Apple don't want developers to change output route programically, sometimes we can still change output route forcefully when iPhone is not connected to headset/headphone:

AVAudioSession* session = [AVAudioSession sharedInstance];
[session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:nil];
[session setActive:YES error:nil];

this takes effect only when iPhone is not connected to headset/headphone.

like image 131
lixing123 Avatar answered Feb 28 '26 23:02

lixing123



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!