Skip to content

Commit

Permalink
fix: support usb outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
js-seo authored and parkjurung committed Jan 10, 2025
1 parent bd2c1c5 commit 02058a4
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions pagecall/src/main/java/com/pagecall/PagecallWebView.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,39 +226,31 @@ private void updateCommunicationDevice() {
this.nativeBridge.log("deviceChange", "Bluetooth output detected: " + bluetoothDevice.getProductName());
}
return;
} else {
audioManager.stopBluetoothSco();
}

// 2. Headphone (Including earpieces)
AudioDeviceInfo headphoneDevice = null;
// 2. External devices (Headsets, earpieces, ...)
AudioDeviceInfo externalDevice = null;
for (AudioDeviceInfo deviceInfo : devices) {
if (deviceInfo.getType() == AudioDeviceInfo.TYPE_WIRED_HEADPHONES ||
deviceInfo.getType() == AudioDeviceInfo.TYPE_WIRED_HEADSET ||
deviceInfo.getType() == AudioDeviceInfo.TYPE_BUILTIN_EARPIECE) {
headphoneDevice = deviceInfo;
if (deviceInfo.getType() != AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
externalDevice = deviceInfo;
break;
}
}
if (headphoneDevice != null) {
audioManager.stopBluetoothSco();
if (externalDevice != null) {
audioManager.setSpeakerphoneOn(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
audioManager.setCommunicationDevice(headphoneDevice);
audioManager.setCommunicationDevice(externalDevice);
}
if (this.nativeBridge != null) {
this.nativeBridge.log("deviceChange", "Headphone output detected: " + headphoneDevice.getProductName());
this.nativeBridge.log("deviceChange", "External output detected: " + externalDevice.getProductName());
}
return;
}

// 3. Builtin
AudioDeviceInfo builtinDevice = null;
for (AudioDeviceInfo deviceInfo : devices) {
if (deviceInfo.getType() == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
builtinDevice = deviceInfo;
break;
}
}
audioManager.stopBluetoothSco();
AudioDeviceInfo builtinDevice = devices.get(0);
audioManager.setSpeakerphoneOn(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
audioManager.clearCommunicationDevice();
Expand Down

0 comments on commit 02058a4

Please sign in to comment.