Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select Audio device on iPhone

Is there a way to let the user select which device they use for audio output?

In the docs I have found that you can select which route to use by setting kAudioSessionProperty_OverrideAudioRoute to either:

  • kAudioSessionOverrideAudioRoute_None, or
  • kAudioSessionOverrideAudioRoute_Speaker

However I would like to let the user to use their Bluetooth headset to hear the audio.

If you look in Apple's own 'Voice memos' app, in the playback menu there is a button in the top left which lets you choose which audio device to use. When a Bluetooth headset is attached, pressing the button brings up a menu which makes it possible to select between:

  • Bluetooth headset
  • iPhone
  • Speaker

Is there a way to achieve this functionality using standard Apple APIs in my own app?

like image 787
pheelicks Avatar asked Jul 07 '10 09:07

pheelicks


2 Answers

In 3.1 there are two protocols that support outputting audio to bluetooth devices and the use depends on the accessory. The first is A2DP which is used with accessores that support recieving stereo music, and the other is hands free for all handfree accesories. To activate the first option, you need to use the MPVolumeView class which has a volume slider and a audio device selection button, when this view is added to any of the views in the app, it provides a way for the user to set the volume and select a BT device if connected ( this is the only way I found) On the other hand, the second option can be activated using the call

 UInt32 bt = TRUE;
 result = AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryEnableBluetoothInput , sizeof(UInt32), &bt);

The appliction must initialize the audio session and use the corect catagory ( it must support recoding for this to work). After the EnableBluetoothInput is set all Input and output audio will be routed through the handsfree device ( if connected of course :) )

like image 122
Kyle Browning Avatar answered Oct 21 '22 03:10

Kyle Browning


The easiest way is to add a MPVolume control (link to documentation) to your user interface and set showsVolumeSlider = NO and showsRouteButton = YES.

User will have a route button to route the audio to a device of their choice.

like image 34
Topsakal Avatar answered Oct 21 '22 03:10

Topsakal