Listen for audio events
The Video SDK for macOS fires audio-related callbacks through ZMVideoSDKDelegate. Conform to the delegate and implement the callbacks below to react to audio state changes. If you haven't already set up a delegate, see Integrate.
Get notified when a user's audio status has changed
onUserAudioStatusChanged fires when a user mutes, unmutes, connects, or disconnects audio.
func onUserAudioStatusChanged(_ audioHelper: ZMVideoSDKAudioHelper!, userList userArray: [ZMVideoSDKUser]!) {
// userArray contains the users that had an audio status change.
if let userArray = userArray {
for user in userArray {
// Use to check if a user's audio is muted.
// If true, the user is muted. If false, the user is unmuted.
if ((user.getAudioStatus().isMuted) == true) {
// User's audio is muted.
}
// Use to obtain a certain user's audio type.
if let audioType = user.getAudioStatus()?.audioType {
print("User has audio type: \(audioType)")
}
}
}
}
- (void)onUserAudioStatusChanged:(ZMVideoSDKAudioHelper*)audioHelper userList:(NSArray*)userArray {
// userArray contains the users that had an audio status change.
for (int i = 0; i < userArray.count; i++) {
if (userArray[i]) {
// Use to check if a user's audio is muted.
// If true, the user is muted. If false, the user is unmuted.
if ([userArray[i] getAudioStatus].isMuted) {
// User's audio is muted.
}
// Use to obtain a certain user's audio type.
NSLog(@"User has audio type: %lu", [userArray[i] getAudioStatus].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 is triggered whenever their microphone detects a noise.
func onUserActiveAudioChanged(_ audioHelper: ZMVideoSDKAudioHelper!, userList userArray: [ZMVideoSDKUser]!) {
// userArray contains the users that had an active audio change.
if let userArray = userArray {
for user in userArray {
// Use to see if the user is currently talking.
if let audioStatus = user.getAudioStatus(), audioStatus.isTalking, let userName = user.getUserName() {
print("\(userName) began talking.")
}
}
}
}
- (void)onUserActiveAudioChanged:(ZMVideoSDKAudioHelper*)audioHelper userList:(NSArray*)userArray {
// userArray contains the users that had an active audio change.
for (int i = 0; i < userArray.count; i++) {
if (userArray[i]) {
// Use to see if the user is currently talking.
if ([userArray[i] getAudioStatus].isTalking) {
NSLog(@"%@ began talking.", userArray[i].getUserName);
}
}
}
}