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.
- Enable Mic - By using
unmuteMic()function, a participant can publish audio to other participants. - Disable Mic - By using
muteMic()function, a participant can stop publishing audio to other participants. - 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()andmuteMic()throwERROR_ALREADY_IN_REQUESTED_STATEwhen the mic is already in that state, andERROR_OPERATION_IN_PROGRESSwhile an earlier call is still running. To turn the mic on or off based on its current state, checkisMicEnabledofRoomfirst.changeMic(deviceId:)throwsERROR_NO_MICROPHONE_DEVICE_FOUNDfor adeviceIdthat is not available, and also sends it toonError(error:). Passnilto 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

