How to Mute Audio and Adjust Volume During a Video Call in Android Using the Agora SDK
Agora has many features that enhance video call quality and convenience. Muting audio and adjusting the video call’s volume are features that are necessary for any video call app.
In this tutorial, you will learn how to mute Agora video call audio and adjust the video call’s volume in Android using the Agora SDK.
Prerequisites and requirements
- An Agora developer account (see How to Get Started with Agora).
- Knowledge of how to create a live-streaming Android application using Agora. Check out the tutorial here.
- Basic knowledge of Android development.
- Android Studio.
- An Android device.
Adding dependencies in Gradle
Before we start coding, add the following dependencies in your build.gradle file in the app module, and sync to download the Agora third-party library. Ensure that you always use the latest Agora library version:
Adding permissions in the Manifest.xml file
Add the following permissions in the Manifest.xml file:
Creating an instance of the RtcEngine
Now, let’s create an RtcEngine instance by initializing the RtcEngine and passing the IRtcEngineEventHandler and your App ID to the create method. IRtcEngineEventHandler is an abstract class that provides the default implementation. We will use this object instance later to invoke the adjustPlaybackSignalVolume()method, which adjusts the volume of the video call:
Setting up the video call profile
Next, add the following code which sets the profile, orientation, and video configuration of the video call. Set the Channel profile as CHANNEL_PROFILE_COMMUNICATION. This enables all video call participants to send and receive voice and video in a one-to-one call:
Adjusting the volume during a video call by dragging the SeekBar
A SeekBar is a ProgressBar that can be dragged left and right by a thumb. We will use the SeekBar to adjust the volume of the audio file being played or the video call’s volume.
Let’s start by creating a SeekBar object and calling the setOnSeekBarChangeListener:
To adjust the video call’s volume, we will use the adjustPlaybackSignalVolume() method and pass the progress value of the SeekBar to the adjustPlaybackSignalVolume() method. This method changes the volume of the video call.
The volume range of the Agora video call is from 0 to 100. The default volume is 100.
The onProgressChanged() method tracks changes made on the SeekBar when the user drags the SeekBar:
Next, implement the necessary methods of the SeekBar.OnSeekBarChangeListener interface. The onStartTrackingTouch() function adds a notification that the SeekBar has started tracking the user’s touch:
The onStopTrackingTouch() function adds a notification that the SeekBar has stopped tracking the user’s touch:
Muting the video call
To mute the video call we have to set the volume to 0 using the adjustPlaybackSignalVolume() and adjustAudioMixingVolume() methods. Both of these methods must be used when muting the video call’s audio, and they can be called before or after joining a video call:
Integrating the mute and adjust volume features with the Agora Video Call SDK
You have learned how to mute and adjust the volume using the Agora SDK methods in the previous sections. The following code block of the Mute class shows you how to integrate the mute and adjust volume features in a video streaming application:
Testing the app demo
In this tutorial we have learned how to:
- Track the user’s touch using a SeekBar
- Adjust Agora video call volume
- Mute audio during a video call
Yay! you now know how to mute audio and adjust the volume using the Agora SDK.
Thank you for reading. You can learn more about how to adjust the volume here, and you can check out more Agora features on GitHub here. If you want to copy or reference the SDK I was using, check it on GitHub here.
This article was originally posted on the Agora Blog here: