I'm using APPRTCdemo app on android. I'm trying to make it play the sound coming from the other peer as loud as the volume is set in the Android settings. So if the user muted the device, the audio would not be heard. I tried pretty much every Android API call, but nothing seems to have any effect on the volume. These are the things I tried: AudioManager audioManager = (AudioManager)_context.getSystemService(Context.AUDIO_SERVICE); int volume = audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL);
volume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
volume =audioManager.getStreamVolume(AudioManager.STREAM_RING);
volume =audioManager.getStreamVolume(AudioManager.STREAM_ALARM);
volume =audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION);
volume =audioManager.getStreamVolume(AudioManager.STREAM_SYSTEM);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
audioManager.setStreamVolume(AudioManager.MODE_IN_COMMUNICATION, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, 0,AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
audioManager.setStreamMute(AudioManager.MODE_IN_COMMUNICATION, true);
audioManager.setStreamMute(AudioManager.STREAM_SYSTEM, true);
audioManager.setStreamMute(AudioManager.STREAM_RING, true);
audioManager.setStreamMute(AudioManager.STREAM_MUSIC, true);
audioManager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);
I was facing the same issue. I didn't find any documentation about it, but I figured out that you can't mute the AudioManager.STREAM_VOICE_CALL
stream. Even if you set the volume to 0, you can still hear it.
I don't know if this part of Android or a modification made by the manufacturers, but I tested several phones and tablets that had the same behavior.
This can be very easily tested if you try to mute the audio during a phone call, you can press the volume down key as much as you want, but it won't allow you to mute it completely.
I guess the idea behind all this is preventing the users from thinking the calls are not working properly when the only problem is that the audio is muted.
If you want to mute the stream you can do the following:
RemoteStream.audioTracks.get(0).setEnabled(false); //in case you have only one audio track
In case you have more than one audio tracks in the stream you can put it under loop. This is tested code and mute/unmute is working absolutely fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With