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.
This commit is contained in:
parent
67002c903a
commit
3725f698e4
|
@ -63,7 +63,7 @@ class AudioDeviceHandlerGeneric implements
|
||||||
private AudioManager audioManager;
|
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.
|
* This is only used on Android >= M.
|
||||||
*/
|
*/
|
||||||
private final Runnable onAudioDeviceChangeRunner = new Runnable() {
|
private final Runnable onAudioDeviceChangeRunner = new Runnable() {
|
||||||
|
@ -145,7 +145,7 @@ class AudioDeviceHandlerGeneric implements
|
||||||
// Some other application potentially stole our audio focus
|
// Some other application potentially stole our audio focus
|
||||||
// temporarily. Restore our mode.
|
// temporarily. Restore our mode.
|
||||||
if (audioFocusLost) {
|
if (audioFocusLost) {
|
||||||
module.updateAudioRoute();
|
module.resetAudioRoute();
|
||||||
}
|
}
|
||||||
audioFocusLost = false;
|
audioFocusLost = false;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -256,7 +256,7 @@ class AudioModeModule extends ReactContextBaseJavaModule {
|
||||||
if (mode != -1) {
|
if (mode != -1) {
|
||||||
JitsiMeetLogger.i(TAG + " User selected device set to: " + device);
|
JitsiMeetLogger.i(TAG + " User selected device set to: " + device);
|
||||||
userSelectedDevice = device;
|
userSelectedDevice = device;
|
||||||
updateAudioRoute(mode);
|
updateAudioRoute(mode, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -282,7 +282,7 @@ class AudioModeModule extends ReactContextBaseJavaModule {
|
||||||
boolean success;
|
boolean success;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
success = updateAudioRoute(mode);
|
success = updateAudioRoute(mode, false);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
success = false;
|
success = false;
|
||||||
JitsiMeetLogger.e(e, TAG + " Failed to update audio route for mode: " + mode);
|
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;
|
* @return {@code true} if the audio route was updated successfully;
|
||||||
* {@code false}, otherwise.
|
* {@code false}, otherwise.
|
||||||
*/
|
*/
|
||||||
private boolean updateAudioRoute(int mode) {
|
private boolean updateAudioRoute(int mode, boolean force) {
|
||||||
JitsiMeetLogger.i(TAG + " Update audio route for mode: " + mode);
|
JitsiMeetLogger.i(TAG + " Update audio route for mode: " + mode);
|
||||||
|
|
||||||
if (!audioDeviceHandler.setMode(mode)) {
|
if (!audioDeviceHandler.setMode(mode)) {
|
||||||
|
@ -356,7 +356,7 @@ class AudioModeModule extends ReactContextBaseJavaModule {
|
||||||
|
|
||||||
// If the previously selected device and the current default one
|
// If the previously selected device and the current default one
|
||||||
// match, do nothing.
|
// match, do nothing.
|
||||||
if (selectedDevice != null && selectedDevice.equals(audioDevice)) {
|
if (!force && selectedDevice != null && selectedDevice.equals(audioDevice)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,7 +421,16 @@ class AudioModeModule extends ReactContextBaseJavaModule {
|
||||||
*/
|
*/
|
||||||
void updateAudioRoute() {
|
void updateAudioRoute() {
|
||||||
if (mode != -1) {
|
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…
Reference in New Issue