Skip to main content

Volume control

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.

Understand the tech

The following figure shows the typical workflow you integrate into your app in order to publish and subscribe to audio streams.

Product Workflow

This page shows you how to add the following features to your app:

  • Volume control

    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.

Prerequisites

In order to follow this procedure you must have implemented Get Started with Voice Calling.

Project setup

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.

Implement volume control

This section shows how to use Voice SDK to implement volume control in your app, step-by-step.

Implement the user interface

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 </RelativeLayout>:


_20
<SeekBar
_20
android:id="@+id/volumeSeekBar"
_20
android:layout_width="match_parent"
_20
android:layout_height="wrap_content"
_20
android:layout_below="@+id/joinLeaveButton"
_20
android:layout_alignStart="@+id/joinLeaveButton"
_20
android:layout_alignEnd="@+id/joinLeaveButton"
_20
android:layout_marginTop="10dp"
_20
android:max="100"
_20
android:min="0"
_20
android:progress="50" />
_20
_20
<CheckBox
_20
android:id="@+id/muteCheckBox"
_20
android:layout_width="wrap_content"
_20
android:layout_height="wrap_content"
_20
android:layout_below="@id/volumeSeekBar"
_20
android:checked="false"
_20
android:layout_alignStart="@+id/joinLeaveButton"
_20
android:text="Mute" />

Handle the system logic

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 import statements:


_3
import android.widget.SeekBar;
_3
import android.widget.CheckBox;
_3
import android.widget.CompoundButton;

Implement volume control logic

To implement volume control in your app, take the following steps:

  1. 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 MainActivity class:


    _5
    // Volume Control
    _5
    private SeekBar volumeSeekBar;
    _5
    private CheckBox muteCheckBox;
    _5
    private int volume = 50;
    _5
    private int remoteUid = 0; // Stores the uid of the remote user

  2. Store the uid of the remote user

    To adjust the volume or mute a specific remote user, you need the uid of that user. Add the following line to the beginning of the onUserJoined callback, to store the remoteUid:


    _1
    remoteUid = uid;

  3. Adjust or mute the volume

    You use the OnSeekBarChangeListener and OnCheckedChangeListener callbacks to handle the volume change actions taken by the user. In /app/java/com.example.<projectname>/MainActivity, add the following lines to onCreate after SetupVideoSDKEngine();:


    _25
    volumeSeekBar = (SeekBar)findViewById(R.id.volumeSeekBar);
    _25
    volumeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
    _25
    _25
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    _25
    volume = progress;
    _25
    agoraEngine.adjustRecordingSignalVolume(volume);
    _25
    }
    _25
    _25
    public void onStartTrackingTouch(SeekBar seekBar) {
    _25
    //Required to implement OnSeekBarChangeListener
    _25
    }
    _25
    _25
    public void onStopTrackingTouch(SeekBar seekBar) {
    _25
    //Required to implement OnSeekBarChangeListener
    _25
    }
    _25
    });
    _25
    _25
    muteCheckBox = (CheckBox) findViewById(R.id.muteCheckBox);
    _25
    muteCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
    _25
    _25
    @Override
    _25
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    _25
    agoraEngine.muteRemoteAudioStream(remoteUid, isChecked);
    _25
    }
    _25
    });

Test your implementation

To ensure that you have implemented Voice Calling in your app:

  1. Generate a temporary token in Agora Console .

  2. 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.

  1. In Android Studio, open app/java/com.example.<projectname>/MainActivity and update appId, channelName and token with the values from Agora Console.

  2. Connect an Android device to your development device.

  3. 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.

  4. Press Join to connect to the same channel as your web demo.

  5. Test volume control

    1. Speak into your Android device as you move the slider on the SeekBar to the left and then right. You notice the volume decrease and then increase in the web demo app as the recording volume changes.

    2. Tap the Mute CheckBox while you speak into the microphone connected to the web demo app.

      You notice that the remote audio is muted on your Android device.

    3. To test other volume control methods, in onProgressChanged replace the adjustRecordingSignalVolume call with one of the following:


      _6
      agoraEngine.adjustPlaybackSignalVolume(volume);
      _6
      agoraEngine.adjustUserPlaybackSignalVolume(remoteUid,volume);
      _6
      agoraEngine.adjustAudioMixingVolume(volume);
      _6
      agoraEngine.adjustAudioMixingPlayoutVolume(volume);
      _6
      agoraEngine.adjustAudioMixingPublishVolume(volume);
      _6
      agoraEngine.setInEarMonitoringVolume(volume);

      Run the app again and use the volume slider to test the change in the corresponding volume setting.

    4. To test other mute methods, in onCheckedChanged replace the muteRemoteAudioStream call with one of the following:


      _2
      agoraEngine.muteAllRemoteAudioStreams(isChecked);
      _2
      agoraEngine.muteLocalAudioStream(isChecked);

      Run the app again and tap the CheckBox to test the effect of these mute methods.

Reference

This section contains information that completes the information in this page, or points you to documentation that explains other aspects to this product.

Page Content

Voice Calling