The Agora Web SDK allows you to manage the sampling volume of the local audio or the playback volume of the subscribed audio as required by the actual scenario.
Before proceeding, ensure that you have read the quickstart guides and implemented basic real-time audio and video functions in your project.
The SDK provides the setVolume
method for the local audio track and the remote audio track objects, to adjust the sampling volume of the local audio track and the playback volume of the remote audio tracks respectively.
Adjust the playback volume
In the following example, the remoteUser
object represents a subscribed remote user.
// Set the volume to half of the original volume
remoteUser.audioTrack.setVolume(50);
// Set the volume to twice of the original volume
remoteUser.audioTrack.setVolume(200);
// Set the volume to 0
remoteUser.audioTrack.setVolume(0);
Adjust the sampling volume
In the following example, the localAudioTrack
object represents the local audio track.
AgoraRTC.createMicrophoneAudioTrack().then(localAudioTrack => {
// Set the volume to half of the original volume
localAudioTrack.setVolume(50);
// Set the volume to twice of the original volume
localAudioTrack.setVolume(200);
// Set the volume to 0
localAudioTrack.setVolume(0);
});
On some devices, setting the audio level too high may cause audio distortion.