100ms Logo

100ms

Docs

Search docs
/

Mute / Unmute Peer

Mute is something that applies to both audio and video. When you mute audio, you can't be heard by other people i.e your audio is OFF. When you mute a video, you will not be broadcasting your video to other people i.e your video is OFF.

Methods to mute/unmute

This example shows implementation of three methods namely :

1. toggleMicMuteState : To switch local peer's audio on/off.

2. toggleCameraMuteState : To switch local peer's video on/off.

3. switchCamera: Switch camera to the front or rear mode

Let's look at their implementation:

class Meeting implements HMSUpdateListener,HMSActionResultListener{ ... /// To switch local peer's audio on/off. hmsSDK.toggleMicMuteState(); //This toggles the current mic status(mute/unmute) /// To switch local peer's video on/off. hmsSDK.toggleCameraMuteState(); //This toggles current camera status(mute/unmute) /// Switch camera from front or rear mode hmsSDK.switchCamera(); ... }

How to mute microphone

Let's look at how we can mute microphone:

Call toggleMicMuteState on HMSSDK instance

To mute microphone we need to call toggleMicMuteState

class Meeting implements HMSUpdateListener,HMSActionResultListener{ ... /// To switch local peer's audio on/off. hmsSDK.toggleMicMuteState(); //This toggles the current mic status(mute/unmute) ... }

Receive the onTrackUpdate with update type trackUnmuted

After calling toggleMicMuteState we will receive onTrackUpdate with HMSTrackUpdate.trackUnmuted type and track kind as HMSTrackKind.kHMSTrackKindAudio

class Meeting implements HMSUpdateListener,HMSActionResultListener{ bool isMicOff = true; ... void onTrackUpdate( {required HMSTrack track, required HMSTrackUpdate trackUpdate, required HMSPeer peer}) { //To check mute/unmute status for local peer if (peer.isLocal) { if ((track.kind == HMSTrackKind.kHMSTrackKindAudio) && (track.source == "REGULAR") && (trackUpdate == HMSTrackUpdate.trackUnMuted)) { //Here we will receive the trackUnmuted update for audio track of local peer. //i.e. track.isMute will be false isMicOff = track.isMute; } ... } } ... }

How to get the current mute/unmute state

To get the current mute/unmute state for local peer we will use local peer's HMSTrack object.

class Meeting implements HMSUpdateListener,HMSActionResultListener{ bool isMicOff = false; bool isCameraOff = false; ... void onTrackUpdate( {required HMSTrack track, required HMSTrackUpdate trackUpdate, required HMSPeer peer}) { //To check mute/unmute status for local peer if (peer.isLocal) { if (track.kind == HMSTrackKind.kHMSTrackKindAudio && track.source == "REGULAR") { isMicOff = track.isMute; } if (track.kind == HMSTrackKind.kHMSTrackKindVideo && track.source == "REGULAR") { isCameraOff = track.isMute; } } } ... }

Mute Remote peers locally

To mute peers all the peers for yourself HMSSDK provides dedicated methods muteRoomAudioLocally for audio and muteRoomVideoLocally for video. Execution of this method mutes audio and video only locally others will still be able to hear audio and video.

These methods mute/unmute the room audio/video of all the peers for yourself.To mute/unmute certain peer check this

//To mute room audio locally hmsSDK.muteRoomAudioLocally(); //To mute room video locally hmsSDK.muteRoomVideoLocally();

Similarly their counterparts:

//To unmute room audio locally hmsSDK.unMuteRoomAudioLocally(); //To unmute room video locally hmsSDK.unMuteRoomVideoLocally();

If you are looking to Mute other (remote) Peers in Room, checkout the Remote Mute here.


Have a suggestion? Recommend changes ->

Was this helpful?

1234