flutter-webrtc
flutter-webrtc copied to clipboard
Feedback/Echo when turn on speaker in Android devices
Describe the bug
Usually feedback/echo when turn on speaker, caller will hear he/she voice after delay about 500ms.
To Reproduce
Can use example source code of this lib, update newest version lib and build apk file, install on two devices and make a call. If the first time the feedback/echo not happening, try again and usually it will.
Expected behavior
No feedback/echo
Platform information
- Flutter version: 2.8.0
- Plugin version: 8.0.0
- OS: Android
- OS version: 10, 11
Hi @cloudwebrtc I tried log audio mode before start audio capture and found that, audio mode is normal, not communication. So I fixed by add codes to make sure when call getUserAudio() must switch audio mode to communication.
private AudioTrack getUserAudio(ConstraintsMap constraints) {
// Audio mode need set MODE_IN_COMMUNICATION to make sure have best performance audio handle for VOIP call
AudioManager audioManager = (AudioManager) applicationContext.getSystemService(Context.AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
MediaConstraints audioConstraints;
if (constraints.getType("audio") == ObjectType.Boolean) {
audioConstraints = new MediaConstraints();
addDefaultAudioConstraints(audioConstraints);
} else {
audioConstraints = MediaConstraintsUtils.parseMediaConstraints(constraints.getMap("audio"));
}
Log.i(TAG, "getUserMedia(audio): " + audioConstraints);
String trackId = stateProvider.getNextTrackUUID();
PeerConnectionFactory pcFactory = stateProvider.getPeerConnectionFactory();
AudioSource audioSource = pcFactory.createAudioSource(audioConstraints);
return pcFactory.createAudioTrack(trackId, audioSource);
}
It should be updated in next release.
Hi @anhlevfx,
I'm using flutter_webrtc version 0.8.3 and can't see this fix. To which version this fix is applied?
Thanks
Hello @gshomali , You should update local lib by yourself by using my codes above.
Thanks!
Was this implemented in the latest releases?
looks like @vsomayaji fixed this issue, and I'd be happy to accept a PR to close this issue
@cloudwebrtc I'd be happy to open a PR from https://github.com/aira/flutter-webrtc/pull/1, but as I'm neither a WebRTC nor Android expert, there are a couple of things that worry me about the approach:
- Is it safe to set the mode to
MODE_IN_COMMUNICATION
every time someone callsgetUserMedia
requesting an audio track? Or are there times when they would want the mode to stayMODE_NORMAL
? - When should we change the mode back to
MODE_NORMAL
? I found this comment suggesting that if we leave the mode set toMODE_IN_COMMUNICATION
, it can affect the device's audio settings even after the app exits. 😬
Thank you for this awesome plugin!