Prefer bluetooth audio route if available

This commit is contained in:
Sylvain Berfini 2020-08-28 12:40:03 +02:00
parent 9e4a2a48e4
commit ae98121140

View file

@ -158,6 +158,10 @@ class CoreContext(val context: Context, coreConfig: Config) {
}
} else if (state == Call.State.OutgoingInit) {
onOutgoingStarted()
} else if (state == Call.State.OutgoingRinging) {
if (core.callsNb == 1) {
routeAudioToBluetoothIfAvailable(call)
}
} else if (state == Call.State.Connected) {
if (isVibrating) {
Log.i("[Context] Stopping vibration")
@ -166,6 +170,10 @@ class CoreContext(val context: Context, coreConfig: Config) {
isVibrating = false
}
if (call.dir == Call.Dir.Incoming && core.callsNb == 1) {
routeAudioToBluetoothIfAvailable(call)
}
onCallStarted()
} else if (state == Call.State.End || state == Call.State.Error || state == Call.State.Released) {
if (core.callsNb == 0) {
@ -519,4 +527,16 @@ class CoreContext(val context: Context, coreConfig: Config) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
context.startActivity(intent)
}
private fun routeAudioToBluetoothIfAvailable(call: Call) {
for (audioDevice in core.audioDevices) {
if (audioDevice.type == AudioDevice.Type.Bluetooth &&
audioDevice.hasCapability(AudioDevice.Capabilities.CapabilityPlay)) {
Log.i("[Context] Found bluetooth audio device [${audioDevice.deviceName}], routing audio to it")
call.outputAudioDevice = audioDevice
return
}
}
Log.w("[Context] Didn't find any bluetooth audio device, keeping default audio route")
}
}