Mute / Unmute Mic - iOS
This feature allows hosts to communicate with each other during the livestream by enabling or disabling their microphones. While only hosts (participants in SEND_AND_RECV mode) can speak, audience members (in RECV_ONLY mode) can listen to the conversation in real time.
unmuteMic()
-
By using
unmuteMic()function ofRoomclass, the host can publish their audio to other hosts and audience members. -
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 ofRoomclass, the host can stop publishing their audio to other hosts and audience members.
isMicEnabled
- The
isMicEnabledproperty ofRoomclass tells you whether your microphone is on. Before you join, it tells you whether the mic will be turned on at join.
unmuteMic()andmuteMic()areasync throws. Call them withtry awaitinside aTask.- When a call is refused, it throws a
VideoSDKError:ERROR_ACTION_NOT_SUPPORTED_IN_MODE(3066) fromunmuteMic()when the participant is inRECV_ONLYmode, as audience members are, or inSIGNALLING_ONLYmode. Only hosts inSEND_AND_RECVmode can turn the mic on.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 live stream, or after you leave it.ERROR_ROOM_RECONNECTING(3065) while the live stream is reconnecting. The mic stays as it was. Call the method again after it reconnects.ERROR_NO_MICROPHONE_DEVICE_FOUND(3059) when no microphone is available.
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 only toonError(error:)ofRoomEventListener. For example, you getERROR_MICROPHONE_ACCESS_DENIED_OR_DISMISSED(3018) when the user turns down the permission prompt, andERROR_MICROPHONE_PERMISSION_DENIED_BY_OS(3020) when microphone access is off in Settings.
Example
Read isMicEnabled to decide whether to turn the mic on or off.
- 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 theParticipantwith theRTCStreamobject.
Events associated with muteMic
- Every Participant will receive a callback on
onStreamDisabled()of theParticipantwith theRTCStreamobject.
Audio Permissions
Step 1:Begin by ensuring that your application has audio permission to access user's microphone device. Utilize thegetAudioPermissionStatus()method of theVideoSDKclass to check whether permission is granted. It only returns the status. To ask the user, usegetAudioPermission()as shown below.
In case permissions are blocked by the user, the app's permission request dialogue cannot be re-rendered programmatically. In such cases, consider providing guidance to users on manually adjusting their application settings.
- Swift
let audioPermission = VideoSDK.getAudioPermissionStatus() // audio permission status
Request Permissions
-
If permission status is
notDetermined, use thegetAudioPermission()method of theVideoSDKclass to prompt users to grant access to their devices. -
Calling the above method will automatically handle the notDetermined state and prompt the user to grant permission.
- Swift
class LiveStreamViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// UI Setup
setupUI()
// prompt user to grant permission when the app starts
VideoSDK.getAudioPermission()
}
func setupUI() {
// your UI code
}
}
API Reference
The API references for all the methods and events utilized in this guide are provided below.
Got a Question? Ask us on discord

