Monitoring the Volume
Update time: 2025/06/11 16:45:39
In some audio co-hosting or video conferencing scenarios, developers are typically required to know the volume of speakers at the application layer for the UI volume display or dynamic adjustment of the view layout according to their volume.
NERTC SDK enables monitoring the volume transmitted by all members in a room.
Method
-
Call the API enableAudioVolumeIndication, to enable a prompt on the speaker’s volume.
This method allows the SDK to give feedback on the current speaker and their volume to the App periodically.
-
In the proxy method onLocalAudioVolumeIndication, the callback that reports the instant volume of the local users in the room.
-
In the proxy method onRemoteAudioVolumeIndication, the callback that reports the current speaker in the room and the speaker's volume.
Sample code
boolean enableActiveSpeaker = true;
NERtcEx.getInstance().enableAudioVolumeIndication(enableActiveSpeaker, 500);
public class ChatActivity implements NERtcCallbackEx {
......
@Override
public void onLocalAudioVolumeIndication(int volume) {
if (volume > 0) {
mUserSelf.speakerView.setText("Speaking: " + volume);
} else {
mUserSelf.speakerView.setText("");
}
}
@Override
public void onRemoteAudioVolumeIndication(NERtcAudioVolumeInfo[] volumeArray, int totalVolume) {
for (int i = 0, len = mRemoteUserMap.size(); i < len; i++) {
MultiChatUser user = mRemoteUserMap.valueAt(i);
if (user.speakerView != null) {
user.speakerView.setText("");
}
}
if (volumeArray == null) {
return;
}
for (NERtcAudioVolumeInfo volumeInfo : volumeArray) {
MultiChatUser user = mRemoteUserMap.get(volumeInfo.uid);
if (user != null) {
String text = String.format(Locale.CHINA, "Speaking: %d", volumeInfo.volume);
user.speakerView.setText(text);
user.volume = volumeInfo.volume;
}
}
}
}





