Volume control and mute
This page shows you how to configure volume settings for audio recording, audio playback, and for the playback of music files.
Understand the tech
Agora Video SDK supports adjusting the audio volume for both recording and playback to meet practical application use-cases. For example, during a two-person call, you can mute a remote user by adjusting the playback volume setting to 0.
The figure below shows the workflow of adjusting the volume.
Volume adjust workflow
Playback refers to transmitting an audio signal from a sender to a recipient, where it is played back through a playback device.
In-ear monitoring refers to the process of playing audio captured by a device.
Recording refers to the process in which audio signals are captured by a recording device and then sent to the transmitter.
Prerequisites
Ensure that you have implemented the SDK quickstart in your project.
Implement volume control
Use one or more of the following volume control methods to adjust volume settings.
Adjust the playback volume
Call adjustPlaybackSignalVolume
or adjustUserPlaybackSignalVolume
to adjust the volume of the audio playback signal.
- Java
- Kotlin
int volume = 50;int uid = 123456;// Set the local playback volume for all remote users mRtcEngine.adjustPlaybackSignalVolume(volume);// Set the local playback volume for a specific remote user. For example, a user with uid=123mRtcEngine.adjustUserPlaybackSignalVolume(uid, volume);
val volume = 50val uid = 123456// Set the local playback volume for all remote usersmRtcEngine.adjustPlaybackSignalVolume(volume)// Set the local playback volume for a specific remote user (e.g., user with uid=123)mRtcEngine.adjustUserPlaybackSignalVolume(uid, volume)
Adjust the in-ear monitoring volume
During the process of audio capture, mixing, and playback, Agora enables you to adjust the in-ear monitoring volume. Enable and set the volume using enableInEarMonitoring
and setInEarMonitoringVolume
.
- Java
- Kotlin
// Enable in-ear monitoringmRtcEngine.enableInEarMonitoring(true);int volume = 50;// Adjust in-ear monitoring volumemRtcEngine.setInEarMonitoringVolume(volume);
// Enable in-ear monitoringmRtcEngine.enableInEarMonitoring(true)val volume = 50// Adjust in-ear monitoring volumemRtcEngine.setInEarMonitoringVolume(volume)
Adjust the recording volume
Call adjustRecordingSignalVolume
to adjust the volume of the audio recording signal.
- Java
- Kotlin
ChannelMediaOptions options = new ChannelMediaOptions();options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER;mRtcEngine.joinChannel(token, channelName, 1234, options);// Adjust the recording signal volume to 50int vol = 50;mRtcEngine.adjustRecordingSignalVolume(vol);
// Create ChannelMediaOptions and set client roleval options = ChannelMediaOptions().apply { clientRoleType = Constants.CLIENT_ROLE_BROADCASTER}// Join channelmRtcEngine.joinChannel(token, channelName, 1234, options)// Adjust the recording signal volume to 50val vol = 50mRtcEngine.adjustRecordingSignalVolume(vol)
When configuring audio settings, it's essential to understand the default behavior and the options available. Here are the key points to keep in mind:
- The SDK defaults to a device volume of
85
when using the recording device to capture audio signals. - A volume of
0
means mute, and a volume of255
represents the maximum volume of the device. - If the SDK detects that the recording volume is too low in the current environment, it automatically increases the volume of the recording device.
- The volume of the recording device directly influences the global volume of the device.
- If the default recording device volume does not meet your requirements, adjust it by regulating the signal amplitude captured by the microphone or sound card.
Mute and unmute users
To mute or unmute the local audio stream, call muteLocalAudioStream
:
- Java
- Kotlin
// Stop publishing the local audio stream mRtcEngine.muteLocalAudioStream(true); // Resume publishing the local audio stream mRtcEngine.muteLocalAudioStream(false);
// Stop publishing the local audio streammRtcEngine.muteLocalAudioStream(true)// Resume publishing the local audio streammRtcEngine.muteLocalAudioStream(false)
To mute or unmute a remote user, call muteRemoteAudioStream
with the uid
of the remote user:
- Java
- Kotlin
// Stop subscribing to the audio stream of the remote user mRtcEngine.muteRemoteAudioStream(remoteUid, true); // Resume subscribing to the audio stream of the remote user mRtcEngine.muteRemoteAudioStream(remoteUid, false);
// Stop subscribing to the audio stream of the remote usermRtcEngine.muteRemoteAudioStream(remoteUid, true)// Resume subscribing to the audio stream of the remote usermRtcEngine.muteRemoteAudioStream(remoteUid, false)
Get volume information of users
Video SDK enables you to obtain the user IDs and corresponding volumes of the three users with the highest instantaneous volumes in a channel during the process of audio recording, mixing, and playback. You use the onAudioVolumeIndication
callback to obtain this information. A returned uid
of 0
in the callback indicates the local user.
- Java
- Kotlin
private final IRtcEngineEventHandler mRtcEventHandler = new IRtcEngineEventHandler() { // ... // Retrieve the user IDs of the three users with the highest instantaneous speaking volume, // their respective volumes, and determine whether the local user is speaking. @Override public void onAudioVolumeIndication(AudioVolumeInfo[] speakers, int totalVolume) { }};
private val mRtcEventHandler = object : IRtcEngineEventHandler() { // Retrieve the user IDs of the three users with the highest instantaneous speaking volume, // their respective volumes, and determine whether the local user is speaking. override fun onAudioVolumeIndication(speakers: Array<AudioVolumeInfo>?, totalVolume: Int) { // Your implementation here }}
enableAudioVolumeIndication
to enable reporting of the users' volume in the callback.- Java
- Kotlin
// Enable the onAudioVolumeIndication callback mRtcEngine.enableAudioVolumeIndication(1000, 3, true);
// Enable the onAudioVolumeIndication callbackmRtcEngine.enableAudioVolumeIndication(1000, 3, true)
Reference
This section contains content that completes the information on this page, or points you to documentation that explains other aspects to this product.
API reference
-
adjustRecordingSignalVolume
-
adjustPlaybackSignalVolume
-
adjustUserPlaybackSignalVolume
-
adjustAudioMixingPlayoutVolume
-
enableInEarMonitoring
[2/2] -
setInEarMonitoringVolume
-
onAudioVolumeIndication
-
muteLocalAudioStream
-
muteRemoteAudioStream
Sample projects
Agora offers the following open-source sample project for adjusting recording, playback, and in-ear monitoring volumes for your reference.
- GitHub: JoinChannelAudio