I'm about to go crazy.
I have a recording app. I'm running into a problem that when I open my app, if i'm listening to music on a bluetooth device, it gets automatically routed back to the phone internal speaker.
I want everything to stay the same no matter what. Even when I start recording, if the user is listening to something on a bluetooth speaker, keep doing that. The user has headphones? Keep the music there. Just leave everything as is.
This is how I'm currently initializing my session:
[[AVAudioSession sharedInstance]
setCategory:AVAudioSessionCategoryPlayAndRecord
withOptions:AVAudioSessionCategoryOptionMixWithOthers | AudioSessionCategoryOptionAllowBluetooth
error: nil];
I'm allowing it to play, record, mix with others and allow bluetooth, so why is it re routing the audio output back to the internal speaker???
Thanks
EDIT on May 30th
I managed to get something better but still missing something.
If I add this line:
[[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:nil];
The music stays in the bluetooth device BUT it sounds horrible.
According to this answer: https://stackoverflow.com/a/18541874/517688 it's because
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
So there is no way to keep everything the same without distorting sound when using a Blueetooth device??
With iOS 10, Apple added the option AVAudioSessionCategoryOptionAllowBluetoothA2DP
. They also changed the meaning of AudioSessionCategoryOptionAllowBluetooth
to only allow output using the HFP Bluetooth profile, which is where you get the low quality audio output.
If you use this new option in place of the AudioSessionCategoryOptionAllowBluetooth
option in your code snippet, it will allow high quality output but disallow low quality audio output.
Here's the online documentation for the options, but unfortunately there's no description for the new iOS 10 options online. You can see more detail in the in-code documentation for AVAudioSession.h
.
https://developer.apple.com/reference/avfoundation/avaudiosessioncategoryoptions?language=objc
Unfortunately I got this answer directly from Apple Technical Support
There is no supported way to achieve the desired functionality given the currently shipping system configurations. If you would like for Apple to consider adding support for such features in the future, please submit an enhancement request via the Bug Reporter tool at http://bugreport.apple.com.
So that's it...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With