Audio
You can control user audio for an ongoing session using methods provided by the Video SDK.
Prior to using audio controls, you must request permissions to use the microphone. See the rest of this page for details and Requesting authorization to capture and save media for more.
Check if the user is connected to audio
Before implementing audio controls, you must first check if the user is connected to audio by getting the user's ZoomVideoSDKAudioType.
// Get the user's audioStatus.
if let audioStatus = user.audioStatus() {
// Get the user's audioType.
let audioType = audioStatus.audioType
}
// Get the user's audioStatus.
ZoomVideoSDKAudioStatus *audioStatus = [user audioStatus];
// Get the user's audioType.
ZoomVideoSDKAudioType audioType = [audioStatus audioType];
Connect to audio
If the user is not already connected, connect to the audio through the ZoomVideoSDKAudioHelper.
if audioType == .none {
// User's audio is not connected.
// Get the ZoomVideoSDKAudioHelper to perform audio actions.
if let audioHelper = ZoomVideoSDK.shareInstance()?.getAudioHelper() {
// Connect User's audio.
audioHelper.startAudio()
}
} else {
// User is already connected to audio.
}
if (audioType == ZoomVideoSDKAudioType_None) {
// User's audio is not connected.
// Get the ZoomVideoSDKAudioHelper to perform audio actions.
ZoomVideoSDKAudioHelper *audioHelper = [[ZoomVideoSDK shareInstance] getAudioHelper];
if (audioHelper) {
// Connect User's audio.
[audioHelper startAudio];
}
} else {
// User is already connected to audio.
}
Mute audio
Once connected, you can mute a user's audio by calling muteAudio:
// Get the ZoomVideoSDKAudioHelper to perform audio actions.
if let audioHelper = ZoomVideoSDK.shareInstance()?.getAudioHelper() {
// Mute user.
audioHelper.muteAudio(user)
}
// Get the ZoomVideoSDKAudioHelper to perform audio actions.
ZoomVideoSDKAudioHelper *audioHelper = [[ZoomVideoSDK shareInstance] getAudioHelper];
if (audioHelper) {
// Mute user.
[audioHelper muteAudio:user];
}
Unmute audio
Unmute a user's audio in a similar manner using unmuteAudio:
// Get the ZoomVideoSDKAudioHelper to perform audio actions.
if let audioHelper = ZoomVideoSDK.shareInstance()?.getAudioHelper() {
// Unmute user.
audioHelper.unmuteAudio(user)
}
// Get the ZoomVideoSDKAudioHelper to perform audio actions.
ZoomVideoSDKAudioHelper *audioHelper = [[ZoomVideoSDK shareInstance] getAudioHelper];
if (audioHelper) {
// Unmute user.
[audioHelper unmuteAudio:user];
}
Disconnect from audio
To disconnect completely from audio, use stopAudio:
// Get the ZoomVideoSDKAudioHelper to perform audio actions.
if let audioHelper = ZoomVideoSDK.shareInstance()?.getAudioHelper() {
// Disconnect User's audio.
audioHelper.stopAudio()
}
// Get the ZoomVideoSDKAudioHelper to perform audio actions.
ZoomVideoSDKAudioHelper *audioHelper = [[ZoomVideoSDK shareInstance] getAudioHelper];
if (audioHelper) {
// Disconnect User's audio.
[audioHelper stopAudio];
}
Sound options
By default, Zoom uses noise suppression and echo cancellation to improve the quality of the audio received by your microphone, but these audio filters can interfere with situations that require capturing the full range of audio. See Configuring professional audio settings for Zoom Meetings for details.
Video SDK uses the same technology to improve audio quality, but also supports the ability to turn off these filters to capture the original sound of the microphone, for example, to support the use of a high-quality microphone with built-in audio filters or to capture the full audio range without noise suppression. Capturing the microphone's original sound disables the background noise suppression feature.
Original sound
To enable original sound, set enableMicOriginalInput to true (YES) in the ZoomVideoSDKAudioSettingHelper class. The default setting is false (NO).
ZoomVideoSDKAudioSettingHelper *audioSettingHelper = [[ZoomVideoSDK shareInstance] getAudioSettingHelper];
[audioSettingHelper enableMicOriginalInput:YES];
To disable, set enableMicOriginalInput to false (NO).
[audioSettingHelper enableMicOriginalInput:NO];
Callbacks
The following are examples of some audio callbacks.
Get notified when a user's audio status has changed
func onUserAudioStatusChanged(_ helper: ZoomVideoSDKAudioHelper?, user userArray: [ZoomVideoSDKUser]?) {
// UserArray contains the users that had an audio status change.
// Use helper to perform actions on a user.
if let userArray = userArray {
for user in userArray {
// Use .audioStatus().isMuted to check if a user's audio is muted.
// If isMuted is true, the user is muted. If isMuted is false, the user is not on unmuted.
if let userIsMuted = user.audioStatus()?.isMuted {
if userIsMuted {
// User's audio is not muted.
}
}
// Use .audioStatus().audioType to obtain a certain user's audio type.
if let audioType = user.audioStatus()?.audioType {
print("User has audio type: \\(audioType)")
}
}
}
}
- (void)onUserAudioStatusChanged:(ZoomVideoSDKAudioHelper *)helper user:(NSArray<ZoomVideoSDKUser *> *)userArray {
// UserArray contains the users that had an audio status change.
// Use helper to perform actions on a user.
for (int i = 0; i < userArray.count; i++) {
if (userArray[i]) {
// Use .audioStatus().isMuted to check if a user's audio is muted.
// If isMuted is true, the user is muted. If isMuted is false, the user is unmuted.
if (userArray[i].audioStatus.isMuted) {
// User's audio is muted.
}
// Use .audioStatus.audioType to obtain a certain user's audio type.
NSLog(@"User has audio type: %lu", (unsigned long)userArray[i].audioStatus.audioType);
}
}
}
Get notified when a user's active audio changes
onUserActiveAudioChanged is different from onUserAudioStatusChanged. The SDK calls onUserActiveAudioChanged when a given user's audio changes, it calls onUserAudioStatusChanged when the user's audio status changes.
For example, if the user is unmuted and is using their device's microphone, onUserActiveAudioChanged will be triggered whenever their microphone detects a noise.
/**
* onUserActiveAudioChanged is different from onUserAudioStatusChanged.
* onUserActiveAudioChanged is called when a given user's audio changes, while
* onUserAudioStatusChanged is called when the user's audio status changes. For
* example, if the user is unmuted and is using their device's microphone, this
* callback will be triggered whenever their microphone detects a noise.
*/
func onUserActiveAudioChanged(_ helper: ZoomVideoSDKUserHelper?, users userArray: [ZoomVideoSDKUser]?) {
// UserArray contains the users that had an active audio change.
// Use helper to perform audio actions.
if let userArray = userArray {
for user in userArray {
// Use .audioStatus.talking to see if the user is currently talking.
if let audioStatus = user.audioStatus(), audioStatus.talking, let userName = user.getName() {
print("\\(userName) began talking.")
}
}
}
}
- (void)onUserActiveAudioChanged:(ZoomVideoSDKUserHelper *)helper users:(NSArray<ZoomVideoSDKUser *> *)userArray {
// UserArray contains the users that had an active audio change.
// Use helper to perform audio actions.
for (int i = 0; i < userArray.count; i++) {
if (userArray[i]) {
// Use .audioStatus.talking to see if the user is currently talking.
if (userArray[i].audioStatus.talking) {
NSLog(@"%@ began talking.", userArray[i].getUserName);
}
}
}
}