Pre-call Detection
Function Overview
To ensure a real-time Video Call experience, you can perform network and device detection before the call to identify and resolve issues in advance.
- Network detection: Detects the network environment, which can be used to determine or predict whether the network environment is suitable for publishing/playing streams of a specified bitrate.
- Device detection: Detects whether the local microphone, camera, and speakers are working properly.
This document will introduce how to use ZEGOCLOUD SDK interfaces to implement the above two types of detection.
Prerequisites
Before implementing pre-call network/device detection functions, please ensure:
- You have created a project in the ZEGOCLOUD Console and applied for a valid AppID and AppSign. For details, please refer to Console - Project Information.
- You have integrated the ZEGO Express SDK into your project and implemented basic audio and video stream publishing and playing functions. For details, please refer to Quick Start - Integration and Quick Start - Implementation Process.
Network Detection
Please refer to Network and Performance for operations.
Device Detection
Microphone Detection
Detection Logic
The microphone device detection process is shown in the following figure:
Related Interfaces
1. Start Microphone
Call the startPreview interface to start audio capture without publishing streams.
engine->startPreview(&canvas);2. Check Microphone Permissions
The ZEGOCLOUD SDK will automatically check microphone permissions. If the user has not authorized, it will request user consent; if the user refuses, the user needs to manually enable permissions in system settings.
3. Check if Microphone is Available
Detect whether the device is abnormal through the following callbacks. If no abnormal feedback is detected (you can simultaneously start "4. Check Microphone Audio Data"), and the microphone audio data detection is normal, the microphone device is available.
- Version 2.15.0 and later: Listen to the onLocalDeviceExceptionOccurred callback to detect if the device is abnormal.
- Before version 2.15.0: Listen to the
onDeviceErrorcallback to detect if the device is abnormal.
/**
* Local device exception notification.
*
* Supported versions: 2.15.0 and later.
* Description: Local device exception.
* Trigger timing: This callback is triggered when local audio or video device functions encounter an exception.
*
* @param exceptionType Device exception type.
* @param deviceType The type of device where the exception occurred.
* @param deviceID Device ID. Currently only supports desktop devices, used to identify specific devices; for mobile devices, this parameter will return an empty string.
*/
virtual void onLocalDeviceExceptionOccurred(ZegoDeviceExceptionType /*exceptionType*/, ZegoDeviceType /*deviceType*/, const std::string& /*deviceID*/) {
}4. Check Microphone Audio Data
Call the startSoundLevelMonitor interface to obtain the energy value of the sound captured by the microphone. If the data is normal, the microphone is working properly and can be used for calls.
engine->startSoundLevelMonitor();Camera Detection
Detection Logic
The camera device detection process is shown in the following figure:
Related Interfaces
1. Start Camera
Call the startPreview interface to bind the view for camera preview, and start video capture and preview without publishing streams.
ZegoCanvas canvas(ZegoView(ui->frame_Preview->winId()));
engine->startPreview(&canvas);2. Check Camera Permissions
The ZEGOCLOUD SDK will automatically check camera permissions. If the user has not authorized, it will request user consent; if the user refuses, the user needs to manually enable permissions in system settings.
3. Check if Camera is Available
Detect whether the device is abnormal through the following callbacks. If no abnormal feedback is detected (you can simultaneously start "4. Check if Image is Normal"), and the image display is normal, the device is available.
- Version 2.15.0 and later: Listen to the onLocalDeviceExceptionOccurred callback to detect if the device is abnormal.
- Before version 2.15.0: Listen to the
onDeviceErrorcallback to detect if the device is abnormal.
/**
* Local device exception notification.
*
* Supported versions: 2.15.0 and later.
* Description: Local device exception.
* Trigger timing: This callback is triggered when local audio or video device functions encounter an exception.
*
* @param exceptionType Device exception type.
* @param deviceType The type of device where the exception occurred.
* @param deviceID Device ID. Currently only supports desktop devices, used to identify specific devices; for mobile devices, this parameter will return an empty string.
*/
virtual void onLocalDeviceExceptionOccurred(ZegoDeviceExceptionType /*exceptionType*/, ZegoDeviceType /*deviceType*/, const std::string& /*deviceID*/) {
}4. Check if Image is Normal
If the image displays normally at this time, the camera is working properly and can be used for calls.
Speaker Detection
Detection Logic
The playback device detection process is shown in the following figure:
Related Interfaces
1. Use Media Player to Play Audio File
Call the IZegoMediaPlayer interface to play the audio file you use for testing.
// 1. Create media player.
IZegoMediaPlayer *mediaPlayer = engine->createMediaPlayer();
// 2. Load resource.
std::string currentSelectPath = "xxx";
mediaPlayer->loadResource(currentSelectPath, nullptr);
// 3. Play resource.
mediaPlayer->start();2. Check if Sound is Heard
If you can hear the corresponding audio, the playback device is working properly and can be used for calls. Call the onMediaPlayerStateUpdate callback to view the media player status:
/**
* Player playback state callback.
* @param mediaPlayer The player instance of the callback.
* @param state Player state.
* @param errorCode Error code, please refer to the common error code document: /real-time-video-macos-cpp/error-code#7。
*/
virtual void onMediaPlayerStateUpdate(IZegoMediaPlayer* /*mediaPlayer*/, ZegoMediaPlayerState /*state*/, int /*errorCode*/) { }