Manage in-meeting audio settings

The code on this page works with either the default UI or the custom UI.

Through the SDK, let individual users manage their own various audio settings and control their in-meeting audio state. Additionally, meeting hosts can manage settings for other users and for the meeting as a whole.

Most of the functionality is done through audio settings and in-meeting audio control.

  • IAudioSettingContext from ISettingService for device and join-audio settings.
  • IMeetingAudioController from IMeetingService for in-meeting audio actions.
#include <windows.h>
#include <cstdint>
#include <zoom_sdk.h>
#include <setting_service_interface.h>
#include <meeting_service_interface.h>
#include <meeting_service_components/meeting_audio_interface.h>
#include <meeting_service_components/meeting_configuration_interface.h>
#include <meeting_service_components/meeting_participants_ctrl_interface.h>
#include <meeting_service_components/meeting_ui_ctrl_interface.h>
using namespace ZOOM_SDK_NAMESPACE;
ISettingService* settingService = nullptr;
CreateSettingService(&settingService);
IMeetingService* meetingService = nullptr;
CreateMeetingService(&meetingService);
IAudioSettingContext* audioSettings =
    settingService ? settingService->GetAudioSettings() : nullptr;

Connect to meeting audio

Before joining a meeting, enable or disable auto connect to the meeting audio.

if (audioSettings) {
    audioSettings->EnableAutoJoinAudio(true);
}

You can also be update the current meeting's meeting settings to mute by default upon joining the meeting using EnableAlwaysMuteMicWhenJoinVoip. Unless the meeting explicitly prevents participants from unmuting themselves, any client instances can override this behavior.

if (audioSettings) {
    audioSettings->EnableAlwaysMuteMicWhenJoinVoip(true);
}

After joining a meeting, the SDK instance may not automatically connect to the meeting audio. To send or receive audio in the meeting, connect the SDK to the audio channel.

if (meetingService) {
    IMeetingAudioController* audioController =
        meetingService->GetMeetingAudioController();
    IMeetingParticipantsController* participantsController =
        meetingService->GetMeetingParticipantsController();
    IUserInfo* myself =
        participantsController ? participantsController->GetMySelfUser() : nullptr;
    if (audioController && myself &&
        myself->GetAudioJoinType() == AUDIOTYPE_NONE) {
        audioController->JoinVoip();
    }
}

Once connected, the SDK can also disconnect from the audio channel. After disconnecting from audio, the SDK will no longer be able to send or receive audio until it reconnects.

if (meetingService) {
    IMeetingAudioController* audioController =
        meetingService->GetMeetingAudioController();
    IMeetingParticipantsController* participantsController =
        meetingService->GetMeetingParticipantsController();
    IUserInfo* myself =
        participantsController ? participantsController->GetMySelfUser() : nullptr;
    if (audioController && myself &&
        myself->GetAudioJoinType() == AUDIOTYPE_VOIP) {
        audioController->LeaveVoip();
    }
}

Check whether a specific user is connected to the audio channel by checking their audio type against either IUserInfo::GetAudioJoinType() or IUserAudioStatus::GetAudioType():AUDIOTYPE_VOIP means that they're connected to the meeting audio channel, AUDIOTYPE_PHONE means that they're using audio from their phone, and AUDIOTYPE_NONE means that they aren't connected.

IUserInfo* user = participantsController
    ? participantsController->GetUserByUserID(userId)
    : nullptr;
if (user) {
    AudioType audioType = user->GetAudioJoinType();
    // AUDIOTYPE_VOIP, AUDIOTYPE_PHONE, or AUDIOTYPE_NONE
}
// Or inside IMeetingAudioCtrlEvent::onUserAudioStatusChange(...)
IUserAudioStatus* userAudioStatus = /* item from lstAudioStatusChange */;
if (userAudioStatus) {
    AudioType audioType = userAudioStatus->GetAudioType();
}

Depending on your audio connection, you can also hide the audio dialog that appears when joining the meeting when you are not connected to audio using IMeetingConfiguration.

if (meetingService) {
    IMeetingConfiguration* meetingConfiguration =
        meetingService->GetMeetingConfiguration();
    if (meetingConfiguration) {
        meetingConfiguration->DisableAutoShowSelectJoinAudioDlgWhenJoinMeeting(true);
    }
}

Managing audio speaker

Get the list of available speakers using GetSpeakerList(), and check which of the speakers is selected based on the IsSelectedDevice state. Then call the SelectSpeaker to change to another speaker.

if (audioSettings) {
    IList<ISpeakerInfo*>* speakerList = audioSettings->GetSpeakerList();
    if (speakerList) {
        for (int i = 0; i < speakerList->GetCount(); ++i) {
            ISpeakerInfo* device = speakerList->GetItem(i);
            if (device && device->IsSelectedDevice()) {
                wprintf(L"Selected speaker: %s - %s\n",
                    device->GetDeviceName(),
                    device->GetDeviceId());
            }
        }
    }
    audioSettings->SelectSpeaker(L"Device_ID", L"Device_Name");
}

Managing audio microphone

Get the list of available speakers using GetMicList() and check which of the speakers are selected based on IsSelectedDevice state. Then call the SelectMic to change to another microphone.

if (audioSettings) {
    IList<IMicInfo*>* micList = audioSettings->GetMicList();
    if (micList) {
        for (int i = 0; i < micList->GetCount(); ++i) {
            IMicInfo* device = micList->GetItem(i);
            if (device && device->IsSelectedDevice()) {
                wprintf(L"Selected mic: %s - %s\n",
                    device->GetDeviceName(),
                    device->GetDeviceId());
            }
        }
    }
    audioSettings->SelectMic(L"Device_ID", L"Device_Name");
}

Mute or unmute audio

Mute the local user's audio with IMeetingAudioController. Additionally, if the meeting supports participants muting or unmuting their own audio, use the MuteAudio(userId) or UnMuteAudio(userID).

if (meetingService) {
    IMeetingAudioController* audioController =
        meetingService->GetMeetingAudioController();
    IMeetingParticipantsController* participantsController =
        meetingService->GetMeetingParticipantsController();
    IUserInfo* myself =
        participantsController ? participantsController->GetMySelfUser() : nullptr;
    if (audioController && myself) {
        // Mute self
        audioController->MuteAudio(myself->GetUserID());
        // Unmute self if allowed
        if (audioController->CanUnMuteBySelf()) {
            audioController->UnMuteAudio(myself->GetUserID());
        }
    }
}

If the current user is the meeting's host, they can mute the other meeting participants' audio. For privacy reasons, the host cannot force another participant to unmute their audio.

if (meetingService) {
    IMeetingAudioController* audioController =
        meetingService->GetMeetingAudioController();
    if (audioController) {
        audioController->MuteAudio(targetUserId);
    }
}

The host or co-host can also request that another participant unmute.

if (meetingService) {
    IMeetingAudioController* audioController =
        meetingService->GetMeetingAudioController();
    if (audioController) {
        audioController->UnMuteAudio(targetUserId);
    }
}

The host can also mute all attendees' audio simultaneously.

if (meetingService) {
    IMeetingAudioController* audioController =
        meetingService->GetMeetingAudioController();
    if (audioController) {
        audioController->MuteAudio(0, true);
    }
}

Stop incoming audio

The SDK supports stopping your device from receiving audio while staying connected to the audio channel. This lets your microphone continue capturing audio and sending it to other meeting participants, and prevents your device from playing any audio produced by others.

if (meetingService) {
    IMeetingAudioController* audioController =
        meetingService->GetMeetingAudioController();
    if (audioController) {
        audioController->StopIncomingAudio(
            !audioController->IsIncomingAudioStopped());
    }
}