Introduction

To ensure smooth communication, we recommend conducting a media device test before joining a channel to check whether the microphone or camera works properly. This function applies to scenarios that have high-quality requirements, such as online education.

Implementation

Recording device test

Call the startRecordingDeviceTest method to test whether the local audio recording device, such as the microphone, is working properly.

To conduct the test, the user speaks, and the SDK reports the audio volume information in the onAudioVolumeIndication callback. A UID of 0 indicates the local user.

When the test finishes, call the stopRecordingDeviceTest method to stop the current test.

// Initialize the parameter object.
RtcEngineParameters rep(*lpRtcEngine);

// Enumerate all audio devices.
AAudioDeviceManager* lpDeviceManager = new AAudioDeviceManager(lpRtcEngine);
IAudioDeviceCollection *lpRecordingDeviceCollection = (*lpDeviceManager)->enumerateRecordingDevices();

UINT lCount = (UINT) lpRecordingDeviceCollection->getCount();

CString strDeviceName;
CString strDeviceID;

for (UINT nIndex = 0; nIndex < lCount; nIndex++){
    int nRet = lpRecordingDeviceCollection->getDevice(nIndex, strDeviceName, strDeviceID);
    ...
}

// Select an audio capture device.
lpDeviceManager->setRecordingDevice(strDeviceID); // device ID chosen

// Implement the audio volume callback.
virtual void onAudioVolumeIndication(const AudioVolumeInfo* speakers, unsigned int speakerNumber, int totalVolume) {
        (void)speakers;
        (void)speakerNumber;
        (void)totalVolume;
    }

// Enable the audio volume callback.
rep.enableAudioVolumeIndication(1000, // Callback interval (ms)
    10 // Smoothness
    );

// Start the audio capture device test.
(*lpDeviceManager)->startRecordingDeviceTest(1000);

// Stop the audio capture device test.
(*lpDeviceManager)->stopRecordingDeviceTest();

Playback Device Test

Call the startPlaybackDeviceTest method to test whether the local audio playback device, such as the speaker, is working properly.

To conduct the test, specify an audio file for playback. If you can hear the audio file, the audio playback device works properly.

When the test finishes, call the stopPlaybackDeviceTest method to stop the current test.

// Initialize the parameter object.
RtcEngineParameters rep(*lpRtcEngine);

AAudioDeviceManager* lpDeviceManager = new AAudioDeviceManager(lpRtcEngine);
IAudioDeviceCollection *lpPlaybackDeviceCollection = (*lpDeviceManager)->enumeratePlaybackDevices();

UINT lCount = (UINT) lpPlaybackDeviceCollection->getCount();

CString strDeviceName;
CString strDeviceID;

for (UINT nIndex = 0; nIndex < lCount; nIndex++){
    int nRet = lpPlaybackDeviceCollection->getDevice(nIndex, strDeviceName, strDeviceID);
    ...
}

// Select an audio playback device.
lpDeviceManager->setPlaybackDevice(strDeviceID); // device ID chosen

// Start the audio capture device test, and you will hear the audio from the external device.
// You do not need to call `enableAudioVolumeIndication`, because you can directly hear the audio.

#ifdef UNICODE
    CHAR wdFilePath[MAX_PATH];
    ::WideCharToMultiByte(CP_UTF8, 0, filePath, -1, wdFilePath, MAX_PATH, NULL, NULL);
    (*lpDeviceManager)->startPlaybackDeviceTest(wdFilePath);
#else
    (*lpDeviceManager)->startPlaybackDeviceTest(filePath);
#endif

// Stop the audio capture device test.
(*lpDeviceManager)->stopPlaybackDeviceTest();

API Reference

Considerations

  • Ensure that your audio or video device is not being used by any third-party app when you conduct the test.
  • After the test finishes, ensure that you call the corresponding stop method to stop the current test before calling the joinChannel method.