Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android webRTC audio volume

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);
like image 356
Michael P Avatar asked Jul 27 '15 19:07

Michael P


2 Answers

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.

like image 89
Lucas L. Avatar answered Oct 06 '22 00:10

Lucas L.


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.

like image 26
Alex Morrison Avatar answered Oct 05 '22 22:10

Alex Morrison