Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 7 Bluetooth Output not working for AVAudioSessionCategoryPlayAndRecord

In my app, if iPhone is connected to Bluetooth headset, play sound with Bluetooth. Else use default speaker.

Here's my code

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:nil];
[[AVAudioSession sharedInstance] setMode:AVAudioSessionModeVoiceChat error:nil];
[[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];

However, when I tried to use category setCategory:AVAudioSessionCategoryPlayAndRecord. Route to bluetooth device stopped working.. I don't know why. Because by right, the bluetooth option should only work for Record or PlayAndRecord category...

/* only valid with AVAudioSessionCategoryRecord and AVAudioSessionCategoryPlayAndRecord */

Addition: Can I have bluetooth for output ONLY (input still use default Mic from phone)?

UPDATE

I changed the order by calling setMode first, followed by setCategory. It works for the first time running the application (a call). When I tried to do the same action again, currentRoute still gave me output = Bluetooth but the actual output returns to default phone front speaker.

like image 927
xialin Avatar asked Dec 15 '13 16:12

xialin


1 Answers

It has been a while since I post this question and I kind forgot what exactly the problem is... If I remembered correctly it's due to another lib that kept rewriting the output route. somehow I fixed it and made it work the way I want.

I contributed the code to Jawbone's AudioSessionManager lib. Hope that helps.

like image 62
xialin Avatar answered Oct 21 '22 23:10

xialin