Mute / Unmute Mic - iOS
Muting and Unmuting your microphone refers to turning your microphone off and on, respectively.
When you mute your microphone, you prevent any sound from your microphone from being transmitted to other room participants, while unmuting it allows others to hear you.
unmuteMic()
-
By using
unmuteMic()function of theRoomclass, local participant can publish audio to other participants.- You can call this method when the local participant is not broadcasting any audio to others.
-
Audio stream of the participant can be accessed from the
onStreamEnabledevent ofParticipantEventListener.
muteMic()
-
By using
muteMic()function of theRoomclass, local participant can stop publishing audio to other participants. -
You can call this method when the local participant is broadcasting any audio to others.
unmuteMic()andmuteMic()areasync throws. Call them withtry awaitinside aTask.- When a call is refused, it throws a
VideoSDKError:ERROR_ALREADY_IN_REQUESTED_STATE(3054) when the mic is already on, or already off.ERROR_OPERATION_IN_PROGRESS(3055) while an earlier mic call is still running.ERROR_ACTION_PERFORMED_BEFORE_ROOM_JOINED(3035) before you join the room, or after you leave it.ERROR_ROOM_RECONNECTING(3065) while the room is reconnecting. The mic stays as it was. Call the method again after the room reconnects.ERROR_NO_MICROPHONE_DEVICE_FOUND(3059) when no microphone is available.ERROR_ACTION_NOT_SUPPORTED_IN_MODE(3066) fromunmuteMic()when the room is inRECV_ONLYorSIGNALLING_ONLYmode.
unmuteMic()returns before the microphone opens. If the microphone then fails to open, for example because the user denied microphone access or another app is using the microphone, the SDK turns the mic off and sends the error, such asERROR_MICROPHONE_ACCESS_DENIED_OR_DISMISSED, only toonError(error:).
Example
Read room.isMicEnabled to know whether your mic is on.
- Swift
@IBAction func micButtonTapped(_ sender: Any) {
Task {
do {
guard let room = self.room else { return }
if !room.isMicEnabled {
// enable/unmute mic
try await room.unmuteMic()
} else {
// disable/mute mic
try await room.muteMic()
}
} catch let error as VideoSDKError where error == .ERROR_OPERATION_IN_PROGRESS {
// an earlier tap is still running
} catch {
print("Could not change the mic: \(error)")
}
}
}
Events associated with unmuteMic
- Every Participant will receive a callback on
onStreamEnabled()of theParticipantwithStreamobject.
Events associated with muteMic
- Every Participant will receive a callback on
onStreamDisabled()of theParticipantwithStreamobject.
- Swift
extension RoomViewController: ParticipantEventListener {
//Callback for when the participant starts a stream
func onStreamEnabled(_ stream: RTCStream, forParticipant participant: Participant) {
if stream.kind == .audio {
print("new audio stream enabled")
}
}
//Callback for when the participant stops a stream
func onStreamDisabled(_ stream: RTCStream, forParticipant participant: Participant) {
if stream.kind == .audio {
print("new audio stream disabled")
}
}
}
API Reference
The API references for all the methods and events utilised in this guide are provided below.
Got a Question? Ask us on discord

