Skip to main content
Version: 4.x.x

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 the Room class, 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 onStreamEnabled event of ParticipantEventListener.

muteMic()​

  • By using muteMic() function of the Room class, local participant can stop publishing audio to other participants.

  • You can call this method when the local participant is broadcasting any audio to others.

note
  • unmuteMic() and muteMic() are async throws. Call them with try await inside a Task.
  • 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) from unmuteMic() when the room is in RECV_ONLY or SIGNALLING_ONLY mode.
  • 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 as ERROR_MICROPHONE_ACCESS_DENIED_OR_DISMISSED, only to onError(error:).

Example​

Read room.isMicEnabled to know whether your mic is on.

@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​

Events associated with muteMic​

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