Documentation
ExpressVideoSDK Video Call
Documentation
Demo APP
SDK Center
API Center
FAQ
Code Market
Console
Sign Up
Log In
中文站 English
  • Documentation
  • Video Call
  • Upgrade using advanced features
  • Advanced features
  • Improve video quality
  • Test network and devices in advance

Test network and devices in advance

Last updated:2024-09-05 18:32

Introduction

In real-time scenarios requiring high quality and great experience, conducting tests before implementing a call helps troubleshoot in advance and improve the overall user experience.

  • Network test: Detects whether the network quality is suitable for publishing/playing streams at a specified bit rate.
  • Device test: Checks if the microphone, camera, and playback devices work properly.

This document describes how to implement these tests by using ZEGOCLOUD's SDK APIs.

Network test

Monitor Speed Test Callback

Before starting the speed measurement, you can set the callback related to the speed measurement.

When an error occurs during the speed test, the onNetworkSpeedTestError callback will be triggered. Under normal speed measurement conditions, onNetworkSpeedTestQualityUpdate callback will be triggered when network speed quality is updated.

ZegoExpressEngine.getEngine().setEventHandler(new IZegoEventHandler() {
    @Override
    public void onNetworkSpeedTestError(int errorCode, ZegoNetworkSpeedTestType type) {

    }

    @Override
    public void onNetworkSpeedTestQualityUpdate(ZegoNetworkSpeedTestQuality quality, ZegoNetworkSpeedTestType type) {

    }
});

Start Speed Test

Create an instance of ZegoNetworkSpeedTestConfig network speed test configuration, according to the actual situation, set whether to perform uplink and downlink speed test and expected bit rate, call startNetworkSpeedTest interface to start network speed test.

ZegoNetworkSpeedTestConfig config = new ZegoNetworkSpeedTestConfig();

// Perform uplink speed measurement and specify the desired push rate
config.testUplink = true;
config.expectedUplinkBitrate = ZegoExpressEngine.getEngine().getVideoConfig().bitrate;

// Perform downlink speed measurement and specify the desired streaming code rate
config.testDownlink = true;
config.expectedDownlinkBitrate = ZegoExpressEngine.getEngine().getVideoConfig().bitrate;

// start speed test
engine.startNetworkSpeedTest(config);

Stop Speed Measurement

Call stopNetworkSpeedTest interface to stop the network speed test.

After stopping the speed test, you will no longer receive onNetworkSpeedTestError or onNetworkSpeedTestQualityUpdate callback.

engine.stopNetworkSpeedTest();

Device test

Mircophone test

The following diagram shows the process of the microphone test:

1. Turn on the microphone

To enable the audio capturing when no streams are published, call the startPreview method to turn on the microphone.

engine.startPreview();

2. Check the permission

The ZEGO SDK automatically checks whether the microphone permission has been granted.

For Android 6.0, you will need to apply for dynamic permissions for some important permissions, not only apply for static permissions with the AndroidMainfest.xml file. The following code will be needed when applying for the dynamic permissions, among which, the requestPermissions is the method of the Activity.

String[] permissionNeeded = {
    "android.permission.RECORD_AUDIO"};

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    if (ContextCompat.checkSelfPermission(this, "android.permission.RECORD_AUDIO") != PackageManager.PERMISSION_GRANTED) {
        //The numeric value 101 is used for requestCode, which can be any number greater than 0, and it will be transparently passed to the permission request result callback onRequestPermissionsResult.
        requestPermissions(permissionNeeded, 101);
    }
}

3. Check whether the microphone working properly

To check whether the microphone is working properly, listen for the callback accordingly. If no errors occurred (you can implement Step 4 at the same time), and the microphone received data is detected normally, then the microphone is working properly.

  • For SDK 2.15.0 or earlier: Listen for the callback onDeviceError.
/**
* Error notifications of the audio devices.
* @param [deviceName] refers to the device type. For details about the returned value, refer to this: {@link com.zego.zegoliveroom.constants.ZegoConstants.DeviceNameType}
* @param [errorCode] refers to the error code. For details, refer to this: {@link com.zego.zegoliveroom.constants.ZegoConstants.DeviceError}
*/
void onDeviceError(String deviceName, int errorCode);
  • For SDK 2.15.0 or later: Listen for the callback onLocalDeviceExceptionOccurred.
/**
 * Error notifications of the local audio devices.
 * 
 * Version supported: 2.15.0 or later.
 * Description: Error occurred on the local device.
 * Timing: This callback will be triggered when the local audio or video device does not work properly.
 * 
 * @param [exceptionType] refers to the error type.
 * @param [deviceType] refers to the device type.
 * @param [deviceID] refers to the device ID. Currently, only desktop devices can be used to identify specific devices. For mobile devices, this parameter returns an empty string.
 */
public void onLocalDeviceExceptionOccurred(ZegoDeviceExceptionType exceptionType, ZegoDeviceType deviceType, String deviceID){

}

4. Check the captured data

To check the captured data by the microphone, call the startSoundLevelMonitor method to get the sound energy value. If no exceptions are detected, the microphone is ready to be used.

engine.startSoundLevelMonitor();

Camera test

The following diagram shows the process of the camera test:

1. Turn on the camera

To enable the video capturing and local video preview when no streams are published, call the startPreview method to bind the view of the preview of the camera.

engine.startPreview();

2. Check the permission

The ZEGO SDK automatically checks whether the camera permission has been granted.

For Android 6.0, you will need to apply for dynamic permissions for some important permissions, not only apply for static permissions with the AndroidMainfest.xml file. The following code will be needed when applying for the dynamic permissions, among which, the requestPermissions is the method of the Activity.

String[] permissionNeeded = {
    "android.permission.CAMERA"};

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    if (ContextCompat.checkSelfPermission(this, "android.permission.CAMERA") != PackageManager.PERMISSION_GRANTED) {
        //The numeric value 101 is used for requestCode, which can be any number greater than 0, and it will be transparently passed to the permission request result callback onRequestPermissionsResult.
        requestPermissions(permissionNeeded, 101);
    }
}

3. Check whether the camera working properly

To check whether the camera is working properly, listen for the callback accordingly. If no errors occurred (you can implement Step 4 at the same time), and the captured images are displayed normally, then the camera is working properly.

  • For SDK 2.15.0 or earlier: Listen for the callback onDeviceError.
/**
* Error notifications of the devices.
* @param [deviceName] refers to the device type. For details about the returned value, refer to this: {@link com.zego.zegoliveroom.constants.ZegoConstants.DeviceNameType}
* @param [errorCode] refers to the error code. For details, refer to this:{@link com.zego.zegoliveroom.constants.ZegoConstants.DeviceError}
*/
void onDeviceError(String deviceName, int errorCode);
  • For SDK 2.15.0 or later: Listen for the callback onLocalDeviceExceptionOccurred.
/**
 * Error notifications of the local audio devices.
 * 
 * Version supported: 2.15.0 or later.
 * Description: Error occurred on the local device.
 * Timing: This callback will be triggered when the local audio or video device does not work properly.
 * 
 * @param [exceptionType] refers to the error type.
 * @param [deviceType] refers to the device type.
 * @param [deviceID] refers to the device ID. Currently, only desktop devices can be used to identify specific devices. For mobile devices, this parameter returns an empty string.
 */
public void onLocalDeviceExceptionOccurred(ZegoDeviceExceptionType exceptionType, ZegoDeviceType deviceType, String deviceID){

}

4. Check the captured images

If the image captured by the camera are displayed normally, then the camera is ready to be used.

Playback device test

The following diagram shows the process of the playback device test:

1. Play audio files using media player

To play the audio file you used for testing, call the ZegoMediaPlayer method.

// 1. Create a mediaplayer object.
ZegoMediaPlayer mediaPlayer = engine.createMediaPlayer();
// 2. Load the resource.
String resourcePath = "xxx";
mediaPlayer.loadResource(resourcePath, null);
// 3. Play the resource file.
mediaPlayer.start();

2. Check whether the audio can be heard

If you can hear the audio file you played, then the device is working properly and is ready to be used. To listen for and receive the event callbacks related to the status of the media player, call the onMediaPlayerStateUpdate method.

/**
* The event callbacks related to the status of the media player.
* @param [mediaPlayer] refers to the mediaplayer instance. 
* @param [state] refers to the status of the media player.
* @param [errorCode] refers to the error codes. For details, refer to the related document. 
*/
public void onMediaPlayerStateUpdate(ZegoMediaPlayer mediaPlayer, ZegoMediaPlayerState state, int errorCode){}

Error codes

If the value returned by the callback onDeviceError is not 0, refer to the Error codes for more details.

Page Directory
  • Free trial
  • 提交工单
    咨询集成、功能及报价等问题
    电话咨询
    400 1006 604
    Get Consulting
    Scan Wechat QR code