3

In my app I am using the play and record category aka:

UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord;
CheckError( AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,
                                     sizeof (sessionCategory),
                                     &sessionCategory), "Couldn't set audio category");    

In the app any audio that plays would initially output through the receiver until I set this:

UInt32 doChangeDefaultRoute = 1;        
AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof (doChangeDefaultRoute), &doChangeDefaultRoute);  

What I actually want however is for audio to output through a connected bluetooth speaker. For example I have a speaker that I connect with via bluetooth. I am able to play music through it with the native music app. However in my app when using the playandrecord category it only plays on the device. I have tried:

UInt32 allowBluetoothInput = 1;
OSStatus stat = AudioSessionSetProperty (
                                         kAudioSessionProperty_OverrideCategoryEnableBluetoothInput,
                                         sizeof (allowBluetoothInput),
                                         &allowBluetoothInput
                                         );

As well as:

CFStringRef audioRouteOverride = kAudioSessionOutputRoute_BluetoothHFP;

OSStatus s = AudioSessionSetProperty (kAudioSessionProperty_OutputDestination,
                                      sizeof(audioRouteOverride),&audioRouteOverride);

No luck. It seems as though this should be an easy property set but Idk. Any ideas?

Greg Price
  • 2,556
  • 1
  • 24
  • 33
  • I think this link useful for you [how to route iPhone audio to the bluetooth headset][1] [1]: http://stackoverflow.com/questions/2375837/how-to-route-iphone-audio-to-the-bluetooth-headset –  Jun 27 '14 at 05:58

4 Answers4

1

This is possible but your bluetooth device has to be headset or a bluetooth device with a built-in microphone. When you are in the playandrecord category it forces you to use the bluetooth mic as an input. If you do not have a bluetooth mic it won't play to bluetooth either (if you are recording at the same time). Also keep in mind when you are recording and streaming to BT you will only get 8 khz mono.

user2848810
  • 1,187
  • 1
  • 8
  • 12
1

So, first you need to know what kind of bluetooth device it is. Whether it is BluetoothHFP(input & output), BluetoothA2DP(output only) or BluetoothLE (output only). If the device is output only, you won't be able to connect and route the audio in kAudioSessionCategory_PlayAndRecord category. You could try setting the category to kAudioSessionCategory_PlayBack and see if this works.

I encountered the same problem a week ago. My application requires both input and output so I must set the category to kAudioSessionCategory_PlayAndRecord. So I plan to change the session category based on different type of bluetooth device.

seanxiaoxiao
  • 1,282
  • 2
  • 11
  • 23
0

In case someone is also trying to figure this out it is not possible. Take a thorough look at all of the available audio session properties and you will find this to be the case

Greg Price
  • 2,556
  • 1
  • 24
  • 33
0

I think you were over-thinking this. Simply setting the first part to allow bluetooth output and then ensuring that you're routing to none works.

UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_None;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,
                         sizeof (audioRouteOverride),
                         &audioRouteOverride);

I was just testing this exact thing. Then in your route change listener, you should only have to worry about something else, like headphones being plugged in.

kermitology
  • 493
  • 6
  • 12