fix(android) reset audio route after audio focus was lost

Looks like audio devices must be re-set after focus was lost and regained.
Otherwise some devices (tested on a Samsung Galaxy S9) are in a weird state
where the second microphone is not used when speakerphone is on.
pull/8169/head jitsi-meet_5294
Saúl Ibarra Corretgé 4 years ago committed by Saúl Ibarra Corretgé
parent 67002c903a
commit 3725f698e4
  1. 4
      android/sdk/src/main/java/org/jitsi/meet/sdk/AudioDeviceHandlerGeneric.java
  2. 19
      android/sdk/src/main/java/org/jitsi/meet/sdk/AudioModeModule.java

@ -63,7 +63,7 @@ class AudioDeviceHandlerGeneric implements
private AudioManager audioManager;
/**
* {@link Runnable} for running audio device detection the main thread.
* {@link Runnable} for running audio device detection in the audio thread.
* This is only used on Android >= M.
*/
private final Runnable onAudioDeviceChangeRunner = new Runnable() {
@ -145,7 +145,7 @@ class AudioDeviceHandlerGeneric implements
// Some other application potentially stole our audio focus
// temporarily. Restore our mode.
if (audioFocusLost) {
module.updateAudioRoute();
module.resetAudioRoute();
}
audioFocusLost = false;
break;

@ -256,7 +256,7 @@ class AudioModeModule extends ReactContextBaseJavaModule {
if (mode != -1) {
JitsiMeetLogger.i(TAG + " User selected device set to: " + device);
userSelectedDevice = device;
updateAudioRoute(mode);
updateAudioRoute(mode, false);
}
}
});
@ -282,7 +282,7 @@ class AudioModeModule extends ReactContextBaseJavaModule {
boolean success;
try {
success = updateAudioRoute(mode);
success = updateAudioRoute(mode, false);
} catch (Throwable e) {
success = false;
JitsiMeetLogger.e(e, TAG + " Failed to update audio route for mode: " + mode);
@ -321,7 +321,7 @@ class AudioModeModule extends ReactContextBaseJavaModule {
* @return {@code true} if the audio route was updated successfully;
* {@code false}, otherwise.
*/
private boolean updateAudioRoute(int mode) {
private boolean updateAudioRoute(int mode, boolean force) {
JitsiMeetLogger.i(TAG + " Update audio route for mode: " + mode);
if (!audioDeviceHandler.setMode(mode)) {
@ -356,7 +356,7 @@ class AudioModeModule extends ReactContextBaseJavaModule {
// If the previously selected device and the current default one
// match, do nothing.
if (selectedDevice != null && selectedDevice.equals(audioDevice)) {
if (!force && selectedDevice != null && selectedDevice.equals(audioDevice)) {
return true;
}
@ -421,7 +421,16 @@ class AudioModeModule extends ReactContextBaseJavaModule {
*/
void updateAudioRoute() {
if (mode != -1) {
updateAudioRoute(mode);
updateAudioRoute(mode, false);
}
}
/**
* Re-sets the current audio route. Needed when focus is lost and regained.
*/
void resetAudioRoute() {
if (mode != -1) {
updateAudioRoute(mode, true);
}
}

Loading…
Cancel
Save