iOS: Select output on AVAudioSession with headphones attached

1,376 views
Skip to first unread message

Lars Bork

unread,
Dec 17, 2016, 4:57:33 AM12/17/16
to discuss-webrtc
Hello,

I want to change the audio route on an iPhone app which uses webrtc: with no headphones attached everything works fine, I can select between BuiltInReceiver or BuiltInSpeaker:

[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayAndRecord withOptions: AVAudioSessionCategoryOptionDefaultToSpeaker error:&error];


But when I attach headphones to the phone, I cannot change the speaker output anymore. 
Furthermore the behavior is different when the headphones have been attached before the app starts (speaker output still works), or after the app started (output only on headphones).

Do you have an idea how I can handle this?

Thanks a lot!

Henrik Andreasson

unread,
Dec 19, 2016, 3:22:36 AM12/19/16
to discuss-webrtc
The info from Apple states that:

When using AVAudioSessionCategoryOptionDefaultToSpeaker, user gestures will be honored. For example, plugging in a headset will cause the route to change to headset mic/headphones and unplugging the headset will cause the route to change to built-in mic/speaker (as opposed to built-in mic/receiver) when this override has been set.

Also note that it is recommended to use the MPVolumeView API.

I assume (have not verified it) it means that you can switch from earpiece to speaker using the API but that when a user plugs in a wired headset, that action "wins". 

Device selection is something that is best done on an application level and not something that we don't test and maintain on a regular basis using the native APIs.
The exact behavior can differ between devices and OS versions but the available public APIs from Apple should be sufficient.

--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrtc+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/1573b73f-1808-4f45-9803-6ab8c52dfb15%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages