Listen for audio events
The Video SDK for iOS fires audio-related callbacks through ZoomVideoSDKDelegate. Conform to the delegate and implement the callbacks below to react to audio state changes in your session.
If you haven't already set up a delegate, see Integrate for details.
Get notified when a user's audio status has changed
onUserAudioStatusChanged fires when a user mutes, unmutes, connects, or disconnects their audio.
func onUserAudioStatusChanged(_ helper: ZoomVideoSDKAudioHelper?, user userArray: [ZoomVideoSDKUser]?) {
userArray?.forEach { user in
// Use audioStatus().isMuted to check whether a user's audio is muted.
if let userIsMuted = user.audioStatus()?.isMuted, userIsMuted {
// User's audio is muted.
}
// Use audioStatus().audioType to obtain a user's audio type.
if let audioType = user.audioStatus()?.audioType {
print("User has audio type: \\(audioType)")
}
}
}
- (void)onUserAudioStatusChanged:(ZoomVideoSDKAudioHelper *)helper user:(NSArray<ZoomVideoSDKUser *> *)userArray {
for (ZoomVideoSDKUser *user in userArray) {
// Use audioStatus.isMuted to check whether a user's audio is muted.
if (user.audioStatus.isMuted) {
// User's audio is muted.
}
// Use audioStatus.audioType to obtain a user's audio type.
NSLog(@"User has audio type: %lu", (unsigned long)user.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, and 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 is triggered whenever their microphone detects sound.
func onUserActiveAudioChanged(_ helper: ZoomVideoSDKUserHelper?, users userArray: [ZoomVideoSDKUser]?) {
userArray?.forEach { user in
// Use audioStatus().talking to see whether 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 {
for (ZoomVideoSDKUser *user in userArray) {
// Use audioStatus.talking to see whether the user is currently talking.
if (user.audioStatus.talking) {
NSLog(@"%@ began talking.", user.getUserName);
}
}
}
Get notified when mixed audio raw data is received
After you subscribe to raw audio, onMixedAudioRawDataReceived delivers the mixed audio of all users.
func onMixedAudioRawDataReceived(_ rawData: ZoomVideoSDKAudioRawData?) {
// rawData contains the mixed PCM audio for all users.
}
- (void)onMixedAudioRawDataReceived:(ZoomVideoSDKAudioRawData *)rawData {
// rawData contains the mixed PCM audio for all users.
}
Get notified when one-way audio raw data is received
onOneWayAudioRawDataReceived delivers the raw audio of a single user.
func onOneWayAudioRawDataReceived(_ rawData: ZoomVideoSDKAudioRawData?, user: ZoomVideoSDKUser?) {
// rawData contains the PCM audio for the given user.
}
- (void)onOneWayAudioRawDataReceived:(ZoomVideoSDKAudioRawData *)rawData user:(ZoomVideoSDKUser *)user {
// rawData contains the PCM audio for the given user.
}
Get notified when shared audio raw data is received
onSharedAudioRawDataReceived delivers the raw audio shared along with a screen share.
func onSharedAudioRawDataReceived(_ rawData: ZoomVideoSDKAudioRawData?) {
// rawData contains the shared PCM audio.
}
- (void)onSharedAudioRawDataReceived:(ZoomVideoSDKAudioRawData *)rawData {
// rawData contains the shared PCM audio.
}