IOS: using Bluetooth audio output (kAudioSessionProperty_OverrideCategoryEnableBluetoothInput) AudioSession

I have a few questions about the CoreAudio AudioSession framework related to several Bluetooth tasks, and I hope someone can help me with these problems or at least confirm my latest results. Usecase is a navigation application that wants to connect to a Bluetooth-enabled radio control that supports both HFP and A2DP. I have read all AudioSession programming guides, but I still have some open issues, especially when using audio output via Bluetooth.

  • The Bluetooth HFP audio output (kAudioSessionOutputRoute_BluetoothHFP) is only possible if AudioSession kAudioSessionCategory_PlayAndRecord is configured, and you override the following property: kAudioSessionProperty_OverrideCategoryEnableBluetoothInput. It's true? If not, how can I direct the MediaPlayback session example to the kAudioSessionOutputRoute_BluetoothHFP route.

  • Audio output in the background is not possible in the kAudioSessionCategory_PlayAndRecord category. Therefore, I cannot play audio through the HFP Bluetooth route if I am in the background. It's true? Is there a way to send audio via the Bluetooth HFP protocol if the application is in the background?

  • If an A2DP-enabled device is available, my audio route will always automatically switch to the kAudioSessionOutputRoute_BluetoothA2DP route. How can I prevent this route from changing? In addition, how can I specify the output route that I want to have at the moment. With iOS5, you can request all of these route destinations via the kAudioSessionProperty_AudioRouteDescription flag, but I have no idea how I can set it as I want. How can this be achieved?

I hope some of you can help me with these questions. That would really help me in my general understanding of CoreAudio, especially in the AudioSession framework.

+6
source share
2 answers

AudioSession is a complex business.

1. HFP audio output for audio output (kAudioSessionOutputRoute_BluetoothHFP) is only possible if AudioSession kAudioSessionCategory_PlayAndRecord is set and you override the following property: kAudioSessionProperty_OverrideCategoryEnableBluetoothInput. It's true? If not, how can I direct the MediaPlayback session example to the kAudioSessionOutputRoute_BluetoothHFP route.

If you have a Bluetooth headset connected, this is true. You will need both the kAudioSessionCategory_PlayAndRecord audio session and the kAudioSessionProperty_OverrideCategoryEnableBluetoothInput audio session set to play audio from a Bluetooth headset. EnableBluetoothInput affects both input and output in accordance with this . Also remember that sound will play at 8000 Hz due to the limitation of bluetooth input devices. For a device that is connected to A2DP, you can leave it in the kAudioSessionCategoryMediaPlayback audio session and it will play back at a sampling frequency of 44100 Hz.

2. Audio output in the background is not possible with the kAudioSessionCategory_PlayAndRecord category. Therefore, I cannot play audio through the HFP Bluetooth route if I am in the background. It's true? Is there a way to send audio via the HFP Bluetooth protocol if the application is in the background?

Sound playback via Bluetooth HFP is possible in the background if you set the background sound mode in your application. More details here .

3.If there is an available A2DP device, my audio route will always automatically switch to the kAudioSessionOutputRoute_BluetoothA2DP route. How can I prevent this route from changing? In addition, how can I specify the output route that I want to have at the moment. With iOS5, you can request all of these route destinations via the kAudioSessionProperty_AudioRouteDescription flag, but I have no idea how I can set it as I want. How can this be achieved?

Where do you want audio instead? You can try to establish an audio session in PlayAndRecord so that it does not switch to A2DP. This may be beyond your control, although the Audio Session will use what it considers intuitive for the user. If they just plugged in an A2DP device and you only output audio, the A2DP device will be used.

+10
source

All Articles