Todos os produtos
Search
Central de documentação

ApsaraVideo Live:Teste de dispositivos antes da chamada

Última atualização: Jun 30, 2026

Teste o microfone, o alto-falante e a câmera antes de uma chamada para identificar possíveis problemas de hardware com antecedência.

Visão geral

O SDK do Alibaba Real-Time Communication (ARTC) oferece detecção pré-chamada para dispositivos locais de áudio e vídeo, incluindo microfone, alto-falante e câmera. Testar os equipamentos antecipadamente ajuda a evitar falhas inesperadas durante a chamada.

Código de exemplo

Android: Android/ARTCExample/AdvancedUsage/src/main/java/com/aliyun/artc/api/advancedusage/PreJoinChannelTest/PreJoinChannelTestActivity.java.

iOS: iOS/ARTCExample/AdvancedUsage/PreJoinChannelTest/PreJoinChannelTestVC.swift.

Harmony: Harmony/ARTCExample/entry/src/main/ets/pages/advancedusage/PreJoinChannelTestPage.ets.

Implementação

1. Teste de microfone

Inicie o microfone e verifique se não há exceções relatadas e se o volume do áudio capturado está normal.

1. Iniciar teste de microfone

Chame o método startAudioCaptureTest para iniciar a captura de áudio do microfone.

Android

/**
 * @brief Starts the audio capture device test before a call.
 * @details This method starts the audio capture test.
 * - Use the {@link AliRtcAudioVolumeObserver::onTestAudioVolumeCallback} callback to check if audio capture is working properly.
 * @return 
 * - 0: Success.
 * - A non-zero value: An error code.
 * @note This method must be called before joining a channel with {@link joinChannel}.
 */
public abstract int startAudioCaptureTest();

iOS

/**
 * @brief Starts the audio capture device test before a call.
 * @details This method starts audio capture.
 * - Use the {@link onTestAudioVolumeCallback} callback to check if audio capture is working properly.
 * @note This method must be called before joining a channel with {@link joinChannel}.
 */
- (void)startAudioCaptureTest;

Windows

/**
 * @brief Starts the audio capture test before a call.
 * @details This method starts the audio capture test.
 * - Use the {@link AliEngineEventListener::OnTestAudioVolumeCallback} callback to check if audio capture is working properly.
 * @return
 * - 0: Success.
 * - A non-zero value: An error code.
 * @note This method must be called before joining a channel with {@link JoinChannel}.
 */
virtual int StartAudioCaptureTest() = 0;

2. Verificar exceções no microfone

Registre o callback a seguir para detectar exceções de dispositivo. Se não houver exceções relatadas e o volume do microfone estiver normal, o dispositivo estará pronto para uso.

Android

/**
 * @brief Callback for local device exceptions.
 * @param deviceType The device type. For more information, see {@link AliRtcEngine.AliRtcEngineLocalDeviceType}.
 * @param exceptionType The exception type. For more information, see {@link AliRtcEngine.AliRtcEngineLocalDeviceExceptionType}.
 * @param msg The exception message.
 * @note This callback is triggered when an unrecoverable internal device exception occurs. When this callback is triggered, check if the device is available.
 */
public void OnLocalDeviceException(AliRtcEngine.AliRtcEngineLocalDeviceType deviceType, AliRtcEngine.AliRtcEngineLocalDeviceExceptionType exceptionType, String msg){}

iOS

/**
 * @brief Callback for local device exceptions.
 * @param deviceType The device type. For more information, see {@link AliRtcLocalDeviceType}.
 * @param exceptionType The exception type. For more information, see {@link AliRtcLocalDeviceExceptionType}.
 * @param msg The exception message.
 * @note This callback is triggered when an unrecoverable internal device exception occurs. When this callback is triggered, check if the device is available.
 */
- (void)onLocalDeviceException:(AliRtcLocalDeviceType)deviceType exceptionType:(AliRtcLocalDeviceExceptionType)exceptionType message:(NSString *_Nullable)msg;

Windows

/**
 * @brief Callback for local device exceptions.
 * @param deviceType The device type. For more information, see {@link AliEngineLocalDeviceType}.
 * @param exceptionType The exception type. For more information, see {@link AliEngineLocalDeviceExceptionType}.
 * @param msg The exception message.
 * @note This callback is triggered when an unrecoverable internal device exception occurs. When this callback is triggered, check if the device is available.
 */
virtual void OnLocalDeviceException(AliEngineLocalDeviceType deviceType, AliEngineLocalDeviceExceptionType exceptionType, const char* msg){};

3. Verificar o volume do microfone

Registre o callback a seguir para obter o volume do áudio capturado. Valores de volume normais indicam que o microfone funciona corretamente.

Android

/**
 * @brief Callback for the audio volume during the pre-call test.
 * @param volume The audio volume.
 */
public void OnTestAudioVolume(int volume) {}

iOS

/**
 * @brief Callback for the captured audio volume during the pre-call test.
 * @param volume The audio volume.
 */
- (void)onTestAudioVolumeCallback:(int)volume;

Windows

/**
 * @brief Callback for the captured audio volume during the pre-call test.
 * @param volume The audio volume.
 */
virtual void OnTestAudioVolumeCallback(int volume) {}

4. Parar o teste de microfone

Após confirmar o funcionamento correto do microfone, chame stopAudioCaptureTest para interromper o teste.

Android

/**
 * @brief Stops the audio capture test.
 * @return 
 * - 0: Success.
 * - A non-zero value: An error code.
 * @note This method must be called before joining a channel with {@link joinChannel}.
 */
public abstract int stopAudioCaptureTest();

iOS

/**
 * @brief Stops the audio capture test.
 * @note This method must be called before joining a channel with {@link joinChannel}.
 */
- (void)stopAudioCaptureTest;

Windows

/**
 * @brief Stops the audio capture test.
 * @return
 * - 0: Success.
 * - A non-zero value: An error code.
 * @note This method must be called before joining a channel with {@link JoinChannel}.
 */
virtual int StopAudioCaptureTest() = 0;

2. Teste de alto-falante

Reproduza um arquivo de áudio e verifique se a saída de som é audível.

1. Reproduzir um arquivo de áudio

Chame o método playAudioFileTest para reproduzir um arquivo de áudio de teste. A saída audível confirma que o alto-falante funciona corretamente.

Android

/**
 * @brief Plays an audio file for testing.
 * @param filePath The path to the audio file.
 * @return Returns 0 on success, or a negative value on failure.
 * @note This method must be called before joining a channel with {@link joinChannel}.
 */
public abstract int playAudioFileTest(String filePath) ;

iOS

/**
 * @brief Plays an audio file for testing.
 * @param filePath The path to the audio file.
 * @return Returns 0 on success, or a negative value on failure.
 * @note This method must be called before joining a channel with {@link joinChannel}.
 */
- (int)playAudioFileTest:(NSString *_Nonnull)filePath;

Windows

/**
 * @brief Plays an audio file for testing.
 * @param filePath The path to the audio file.
 * @return Returns 0 on success, or a negative value on failure.
 * @note This method must be called before joining a channel with {@link JoinChannel}.
 */
virtual int PlayAudioFileTest(const char* filePath) = 0;

2. Verificar exceções no alto-falante

Registre o callback a seguir para detectar exceções de dispositivo. Caso não haja exceções relatadas e o áudio seja audível, o alto-falante funciona corretamente.

Android

/**
 * @brief Callback for local device exceptions.
 * @param deviceType The device type. For more information, see {@link AliRtcEngine.AliRtcEngineLocalDeviceType}.
 * @param exceptionType The exception type. For more information, see {@link AliRtcEngine.AliRtcEngineLocalDeviceExceptionType}.
 * @param msg The exception message.
 * @note This callback is triggered when an unrecoverable internal device exception occurs. When this callback is triggered, check if the device is available.
 */
public void OnLocalDeviceException(AliRtcEngine.AliRtcEngineLocalDeviceType deviceType, AliRtcEngine.AliRtcEngineLocalDeviceExceptionType exceptionType, String msg){}

iOS

/**
 * @brief Callback for local device exceptions.
 * @param deviceType The device type. For more information, see {@link AliRtcLocalDeviceType}.
 * @param exceptionType The exception type. For more information, see {@link AliRtcLocalDeviceExceptionType}.
 * @param msg The exception message.
 * @note This callback is triggered when an unrecoverable internal device exception occurs. When this callback is triggered, check if the device is available.
 */
- (void)onLocalDeviceException:(AliRtcLocalDeviceType)deviceType exceptionType:(AliRtcLocalDeviceExceptionType)exceptionType message:(NSString *_Nullable)msg;

Windows

/**
 * @brief Callback for local device exceptions.
 * @param deviceType The device type. For more information, see {@link AliEngineLocalDeviceType}.
 * @param exceptionType The exception type. For more information, see {@link AliEngineLocalDeviceExceptionType}.
 * @param msg The exception message.
 * @note This callback is triggered when an unrecoverable internal device exception occurs. When this callback is triggered, check if the device is available.
 */
virtual void OnLocalDeviceException(AliEngineLocalDeviceType deviceType, AliEngineLocalDeviceExceptionType exceptionType, const char* msg){};

3. Parar a reprodução do arquivo de áudio

Após confirmar o funcionamento correto do alto-falante, chame stopAudioFileTest para interromper a reprodução.

Android

/**
 * @brief Stops playing the test audio file.
 * @return Returns 0 on success, or a negative value on failure.
 * @note This method must be called before joining a channel with {@link joinChannel}.
 */
public abstract int stopAudioFileTest();

iOS

/**
 * @brief Stops playing the test audio file.
 * @return Returns 0 on success, or a negative value on failure.
 * @note This method must be called before joining a channel with {@link joinChannel}.
 */
- (int)stopAudioFileTest;

Windows

/**
 * @brief Stops playing the test audio file.
 * @return Returns 0 on success, or a negative value on failure.
 * @note This method must be called before joining a channel with {@link JoinChannel}.
 */
virtual int StopAudioFileTest() = 0;

3. Teste de câmera

Configure a visualização local e inicie a câmera. Uma prévia exibida corretamente, sem callbacks de exceção, indica que a câmera funciona adequadamente.

1. Configurar prévia local

Antes de iniciar a prévia da câmera, chame setLocalViewConfig para configurar a visualize de exibição.

Android

/**
 * @brief Configures the view for local preview.
 * @param viewConfig The display properties for the local video. For more information, see {@link com.alivc.rtc.AliRtcEngine.AliRtcVideoCanvas}.
 * @param track  Only {@link AliRtcVideoTrack#AliRtcVideoTrackCamera} and {@link AliRtcVideoTrack#AliRtcVideoTrackScreen} are supported.
 * @return
 * - 0: Success.
 * - < 0: Failure.
 * @note You can switch the view before or after you join a channel. If canvas or {@link AliRtcVideoCanvas#view} is null, rendering stops.
 *       To change the {@link AliRtcVideoCanvas#renderMode} or {@link AliRtcVideoCanvas#mirrorMode}, call this method again with the new value
 *       while keeping all other canvas properties the same.
 */
public abstract int setLocalViewConfig(AliRtcVideoCanvas viewConfig, AliRtcVideoTrack track);

iOS

/**
 * @brief Configures the view for local preview.
 * @param viewConfig The display properties for the local video. For more information, see {@link AliVideoCanvas}.
 * @param track  Only {@link AliRtcVideoTrackCamera} and {@link AliRtcVideoTrackScreen} are supported.
 * @return
 * - 0: Success.
 * - < 0: Failure.
 * @note You can switch the view before or after you join a channel. If canvas or {@link AliVideoCanvas::view} is nil, rendering stops.
 *       To change the {@link AliVideoCanvas::renderMode} or {@link AliVideoCanvas::mirrorMode}, call this method again with the new value
 *       while keeping all other canvas properties the same.
 */
- (int)setLocalViewConfig:(AliVideoCanvas *_Nullable)viewConfig forTrack:(AliRtcVideoTrack)track;

Windows

/**
 * @brief Configures the view for local preview.
 * @param renderConfig The display properties for the local video. For more information, see {@link AliEngineVideoCanvas}.
 * @param track  Only {@link AliEngineVideoTrackCamera} and {@link AliEngineVideoTrackScreen} are supported.
 * @return
 * - 0: Success.
 * - A non-zero value: Failure.
 * @note You can switch the view before or after you join a channel. If {@link AliEngineVideoCanvas::displayView} is null, rendering stops.
 *       To change the {@link AliEngineVideoCanvas::renderMode} or {@link AliEngineVideoCanvas::mirrorMode}, call this method again with the new value
 *       while keeping all other renderConfig properties the same.
 */
virtual int SetLocalViewConfig(AliEngineVideoCanvas renderConfig,
AliEngineVideoTrack track) = 0;

2. Iniciar a prévia da câmera

Chame o método startPreview para iniciar a prévia da câmera.

Android

/**
 * @brief Starts the local video preview.
 * @details This method starts the local video preview and automatically turns on the camera.
 * @return
 * - 0: Success.
 * - < 0: Failure.
 * @note A preview is not displayed if a view has not been configured with {@link #setLocalViewConfig}, but this does not affect stream ingest.
 * You can call this method before {@link #joinChannel} to start the preview, which automatically turns on the camera.
 */
public abstract int startPreview();

iOS

/**
 * @brief Starts the local video preview.
 * @return
 * - 0: Success.
 * - <0: Failure.
 * @note A preview is not displayed if a view has not been configured by using {@link setLocalViewConfig:forTrack:}.
 * You can call this method before {@link joinChannel:name:onResultWithUserId:} to start the preview, which automatically turns on the camera.
 */
- (int)startPreview;

Windows

/**
 * @brief Starts the local video preview.
 * @return
 * - 0: Success.
 * - A non-zero value: Failure.
 * @note A preview is not displayed if a view has not been configured by using {@link SetLocalViewConfig}.
 *       You can call this method before {@link JoinChannel} to start the preview, which automatically turns on the camera.
 */
virtual int StartPreview(int width = 0, int height = 0) = 0;

3. Verificar exceções na câmera

Registre o callback a seguir para detectar exceções de dispositivo. Se não houver exceções relatadas e a prévia for exibida corretamente, a câmera funciona adequadamente.

Android

/**
 * @brief Callback for local device exceptions.
 * @param deviceType The device type. For more information, see {@link AliRtcEngine.AliRtcEngineLocalDeviceType}.
 * @param exceptionType The exception type. For more information, see {@link AliRtcEngine.AliRtcEngineLocalDeviceExceptionType}.
 * @param msg The exception message.
 * @note This callback is triggered when an unrecoverable internal device exception occurs. When this callback is triggered, check if the device is available.
 */
public void OnLocalDeviceException(AliRtcEngine.AliRtcEngineLocalDeviceType deviceType, AliRtcEngine.AliRtcEngineLocalDeviceExceptionType exceptionType, String msg){}

iOS

/**
 * @brief Callback for local device exceptions.
 * @param deviceType The device type. For more information, see {@link AliRtcLocalDeviceType}.
 * @param exceptionType The exception type. For more information, see {@link AliRtcLocalDeviceExceptionType}.
 * @param msg The exception message.
 * @note This callback is triggered when an unrecoverable internal device exception occurs. When this callback is triggered, check if the device is available.
 */
- (void)onLocalDeviceException:(AliRtcLocalDeviceType)deviceType exceptionType:(AliRtcLocalDeviceExceptionType)exceptionType message:(NSString *_Nullable)msg;

Windows

/**
 * @brief Callback for local device exceptions.
 * @param deviceType The device type. For more information, see {@link AliEngineLocalDeviceType}.
 * @param exceptionType The exception type. For more information, see {@link AliEngineLocalDeviceExceptionType}.
 * @param msg The exception message.
 * @note This callback is triggered when an unrecoverable internal device exception occurs. When this callback is triggered, check if the device is available.
 */
virtual void OnLocalDeviceException(AliEngineLocalDeviceType deviceType, AliEngineLocalDeviceExceptionType exceptionType, const char* msg){};