To use Voice SDK for audio communication, you implement a simple workflow in your app. The app joins a new or an existing channel using an app ID and an authentication token. If a channel of the given name exists within the context of the app ID, the app joins the channel. If the named channel does not exist, a new channel is created that other users may join. Once the app joins a channel, it subscribes to one or more of the audio streams published in the channel. The app also publishes its own audio stream that other users in the channel subscribe to. Each user publishes streams that share their microphone or audio data.
The basics of joining and leaving a channel are presented in the Get Started with Voice Calling. This document explains the common workflows you need to handle in your app.
The following figure shows the typical workflow you integrate into your app in order to publish and subscribe to audio streams.
This page shows you how to add the following features to your app:
Users in a channel often need to adjust the volume for local and remote audio. For example, they may want to increase the input volume from remote users and decrease the local audio recording volume. You use Voice SDK to enable app users to adjust recording and playback volumes. Voice SDK also provides methods to mute local audio, audio from a particular remote user, or audio from all remote users. Voice SDK provides several methods to manage local and remote audio volumes. These methods enable the user to control:
- Recording signal volume: The volume of the signal recorded by the local user.
- Playback signal volume: The playback audio level, after audio mixing, for all remote users, or for a specific remote user.
- In-ear monitoring volume: The volume of their own voice, users hear through wired earphones.
- Audio mixing volume: The mixing volume for local playback and for sending to other users.
- Muting audio streams: Stop or resume playing a specified remote or local audio.
In order to follow this procedure you must have implemented Get Started with Voice Calling.
To create the environment necessary to implement call quality best practice into your app, open the project you created in Get Started with Voice Calling.
This section shows how to use Voice SDK to implement volume control in your app, step-by-step.
In a real-world application, for each volume setting you want the user to control, you typically add a volume control UI element such as a SeekBar to the audio configuration panel. To enable the user to mute local or remote audio, you add a switch or a
CheckBox to the interface for each user. In this example, you add a
SeekBar and a
CheckBox to the UI to test different volume settings.
To add the UI elements, in
/app/res/layout/activity_main.xml, add the following code before
Add the required libraries
To access and use the UI elements, import the corresponding Android libraries. In
/app/java/com.example.<projectname>/MainActivity, add the following to the list of
To implement volume control in your app, take the following steps:
Declare the variables you need
To read, store and apply volume settings, in
/app/java/com.example.<projectname>/MainActivity, add the following declarations to the
uidof the remote user
To adjust the volume or mute a specific remote user, you need the
uidof that user. Add the following line to the beginning of the
onUserJoinedcallback, to store the
Adjust or mute the volume
You use the
OnCheckedChangeListenercallbacks to handle the volume change actions taken by the user. In
/app/java/com.example.<projectname>/MainActivity, add the following lines to
To ensure that you have implemented Voice Calling in your app:
Generate a temporary token in Agora Console .
In your browser, navigate to the Agora web demo and update App ID, Channel, and Token with the values for your temporary token, then click Join.
In Android Studio, open
tokenwith the values from Agora Console.
Connect an Android device to your development device.
In Android Studio, click Run app. A moment later, you see the project installed on your device.
If this is the first time you run your app, grant camera and microphone permissions.
Press Join to connect to the same channel as your web demo.
Test volume control
Speak into your Android device as you move the slider on the
SeekBarto the left and then right. You notice the volume decrease and then increase in the web demo app as the recording volume changes.
Tap the Mute
CheckBoxwhile you speak into the microphone connected to the web demo app.
You notice that the remote audio is muted on your Android device.
To test other volume control methods, in
adjustRecordingSignalVolumecall with one of the following:
Run the app again and use the volume slider to test the change in the corresponding volume setting.
To test other mute methods, in
muteRemoteAudioStreamcall with one of the following:
Run the app again and tap the
CheckBoxto test the effect of these mute methods.
This section contains information that completes the information in this page, or points you to documentation that explains other aspects to this product.