iOS: Using Bluetooth audio output (kAudioSessionProperty_OverrideCategoryEnableBluetoothInput) AudioSession
Asked Answered
H

2

6

I have several questions to the CoreAudio AudioSession framework related to several Bluetooth tasks and I hope someone can help me with these issues or at least can confirm my latest findings. The usecase is a navigation app that wants to connect with a bluetooth enabled radio which supports both, HFP and A2DP. I have read the whole AudioSession Programming Guidelines but I have still some open issues especially using audio output through Bluetooth.

  1. Bluetooth HFP audio output (kAudioSessionOutputRoute_BluetoothHFP) is only possible in case of AudioSession kAudioSessionCategory_PlayAndRecord is set and you are overriding the following property: kAudioSessionProperty_OverrideCategoryEnableBluetoothInput. Is this true? If not, how I can route as an example with the MediaPlayback session to kAudioSessionOutputRoute_BluetoothHFP route.

  2. Audio output in background mode is not possible with the category kAudioSessionCategory_PlayAndRecord. Therefore I can not play sound through an bluetooth HFP route if I am in background. Is this true? Is there a way how to send audio through the Bluetooth HFP protocol if app is in the background?

  3. If there is an A2DP enabled device available my audio route will always switch automatically to the kAudioSessionOutputRoute_BluetoothA2DP route. How can I prevent this route change? In addition how can I specify the output route I wanna have at the moment. With iOS5 it is possible to query all those route destination through the kAudioSessionProperty_AudioRouteDescription flag, but I have no idea how I can set it as I wanna have it. Is it somehow possible to achieve this?

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

Hurdygurdy answered 30/1, 2013 at 10:17 Comment(0)
A
11

AudioSession is tricky business.

1.Bluetooth HFP audio output (kAudioSessionOutputRoute_BluetoothHFP) is only possible in case of AudioSession kAudioSessionCategory_PlayAndRecord is set and you are overriding the following property: kAudioSessionProperty_OverrideCategoryEnableBluetoothInput. Is this true? If not, how I can route as an example with the MediaPlayback session to kAudioSessionOutputRoute_BluetoothHFP route.

If you have a Bluetooth headset connected, then it is true. You will need both kAudioSessionCategory_PlayAndRecord audio session set and kAudioSessionProperty_OverrideCategoryEnableBluetoothInput set to have audio play out of a Bluetooth headset. EnableBluetoothInput affects both input and output according to this. Also remember, the audio will play at 8000 Hz due to the limitation of bluetooth input devices. For a device that is connected that supports A2DP, you can leave it at audio session kAudioSessionCategoryMediaPlayback and it will play at 44100 Hz sample rate.

2.Audio output in background mode is not possible with the category kAudioSessionCategory_PlayAndRecord. Therefore I can not play sound through an bluetooth HFP route if I am in background. Is this true? Is there a way how to send audio through the Bluetooth HFP protocol if app is in the background?

Playing audio through the bluetooth HFP is possible in the background as long as you have set the background audio mode key in your app plist. See more here.

3.If there is an A2DP enabled device available my audio route will always switch automatically to the kAudioSessionOutputRoute_BluetoothA2DP route. How can I prevent this route change? In addition how can I specify the output route I wanna have at the moment. With iOS5 it is possible to query all those route destination through the kAudioSessionProperty_AudioRouteDescription flag, but I have no idea how I can set it as I wanna have it. Is it somehow possible to achieve this?

Where do you want the audio to go instead? You can try to set the audio session to PlayAndRecord to keep it from going to A2DP. This may be out of your control though, Audio Session will use what it deems to be intuitive to the user. If they just connected an A2DP device and you are only outputting audio, the A2DP device will be used.

Astound answered 30/8, 2013 at 21:41 Comment(1)
do you know what's the problem stated here? #20597256Soviet
P
0

they have mention that it will for USB accessories only.

http://developer.apple.com/library/ios/#documentation/AudioToolbox/Reference/AudioSessionServicesReference/Reference/reference.html

Pedicular answered 13/2, 2013 at 7:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.