How to Switch to Speaker Output When Bluetooth Headsets Are Connected

AudioSession input from bluetooth output to line out or speaker

as of iOS 5 this behaviour is not possible, quoting apple technical support

Bluetooth devices are not "Jacked In" devices and therefore any other
audio routing must be user picked and cannot be changed in code. To do
this, you can use the functionality of the MPVolumeView which will
have an extra routing widget viewable allowing the user to specify the
routing of the output.

There's a older thread on the Core Audio mailing list regarding this
functionality but behavior hasn't changed:

http://lists.apple.com/archives/coreaudio-api/2009/Oct/msg00030.html

MPVolumeView reference:

http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPVolumeView_Class/Reference/Reference.html

However the MPVolumeView does not allow you to route the input and output independently.

Cordova detect switch audio mode - built-in speaker to bluetooth speaker

This Cordova plugin might be what you are looking for? https://github.com/saghul/cordova-plugin-audioroute

It's supposed to hook onto AVAudioSessionRouteChangeNotification and detect when the system audio route changes. According to the README You should be able to add the plugin and then place an event listener inside your project like so:

document.addEventListener('audioroute-changed',
function(event) {
console.log('Audio route changed: ' + event.reason);
// code for stuff you want to do
}
);

AVAudioSessionRouteChangeNotification is also mentioned here in a similar question:
Detect (listen to) audio route change in iOS 7

AVAudioSessionRouteChangeNotification documentation:
https://developer.apple.com/documentation/avfoundation/avaudiosessionroutechangenotification

How to use internal mic for input and bluetooth for output

Get rid of allowBluetooth and use allowBluetoothA2DP. You also don't want defaultToSpeaker here.

"Allow Bluetooth" actually means "prefer HFP" which is why the audio is so bad. HFP is a low-bandwidth bidirectional protocol used generally for phone calls. The enum name is very confusing IMO. People get confused about it all the time.

A2DP is a high-bandwidth unidirectional protocol (it doesn't support a microphone). When you request that, the headset's microphone will be disabled, and you'll get the iPhone's microphone by default (provided there isn't some other wired microphone available, but that's very unlikely).



Related Topics



Leave a reply



Submit