Issue
I am trying to create a video calling application using react-native-webrtc and when a call starts and my phone is connected to Bluetooth headphones it always uses my Android phone microphone instead of Bluetooth headphones
Does anyone know how to fix this problem, how do I use the microphone when my Bluetooth headphones are connected
Solution
I also faced this issue, I added a plugin to manage audio routes and add some permissions for Android in the XML file
Android required permissions for video calling app
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="33" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="33" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.MICROPHONE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
Call this code when your WebRTC stream starts it will choose audio route
import HeadphoneDetection from 'react-native-headphone-detection';
HeadphoneDetection.isAudioDeviceConnected().then(async(e) => {
if (e.audioJack) {
console.log("i'm wired headset");
InCallManager.setForceSpeakerphoneOn(false);
InCallManager.chooseAudioRoute("WIRED_HEADSET");
InCallManager.start()
}
else if (e.bluetooth) {
console.log("i'm bluetooth headset",);
InCallManager.setForceSpeakerphoneOn(false);
InCallManager.chooseAudioRoute("BLUETOOTH");
InCallManager.start()
} else {
console.log("i'm others");
if (isHangUp) {
InCallManager.setForceSpeakerphoneOn(false);
InCallManager.stopRingback();
InCallManager.stopRingtone();
InCallManager.stop({ media: 'video', ringback: '_BUNDLE_' });
} else {
InCallManager.setForceSpeakerphoneOn(true);
InCallManager.stopRingback();
InCallManager.stopRingtone();
InCallManager.chooseAudioRoute("SPEAKER_PHONE");
InCallManager.start({ media: 'video' });
}
}
});
Answered By - Shivo'ham
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.