Skip to main content
Version: 4.x.x

Mic Controls - iOS

A participant can start or stop sending their audio to other participants in the room.

This guide will provide an overview of how to enable, disable and change the mic in a room.

  1. Enable Mic - By using unmuteMic() function, a participant can publish audio to other participants.
  2. Disable Mic - By using muteMic() function, a participant can stop publishing audio to other participants.
  3. Change Mic - By using changeMic() function, a participant can change mic.

These methods are async throws. Call them with try await inside a Task.

Enable, Disable, Change Mic​

/// keep track of mic, update it in onStreamEnabled / onStreamDisabled
private var micEnabled = false

@IBAction func micButtonTapped(_ sender: Any) {
Task {
do {
if !micEnabled {
// enable/unmute mic
try await self.room?.unmuteMic()
} else {
// disable/mute mic
try await self.room?.muteMic()
}
} catch {
print("Mic error: \(error)")
}
}
}

/// mic is one of the devices returned by VideoSDK.getMics()
func changeMic(to mic: MicrophoneDeviceInfo) {
Task {
do {
// change mic
try await self.room?.changeMic(deviceId: mic.deviceId)
} catch {
print("Change mic error: \(error)")
}
}
}
note
  • unmuteMic() and muteMic() throw ERROR_ALREADY_IN_REQUESTED_STATE when the mic is already in that state, and ERROR_OPERATION_IN_PROGRESS while an earlier call is still running. To turn the mic on or off based on its current state, check isMicEnabled of Room first.
  • changeMic(deviceId:) throws ERROR_NO_MICROPHONE_DEVICE_FOUND for a deviceId that is not available, and also sends it to onError(error:). Pass nil to use the next microphone. If the mic is off, it only selects the device.
  • If the mic fails to open, for example because microphone access was denied, the error arrives in onError(error:), not at the call.

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