Tous les produits
Search
Centre de documentation

ApsaraVideo Live:Test des appareils avant l'appel

Dernière mise à jour :Aug 19, 2026

Testez votre microphone, vos haut-parleurs et votre caméra avant un appel afin d'identifier rapidement les éventuels problèmes matériels.

Présentation

Le SDK Alibaba Real-Time Communication (ARTC) propose une détection préalable des appareils audio et vidéo locaux, notamment le microphone, les haut-parleurs et la caméra. Ces tests préalables permettent d'éviter les pannes inattendues des appareils pendant un appel.

Exemple de code

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.

Implémentation

1. Test du microphone

Démarrez le microphone et vérifiez qu'aucune exception n'est signalée et que le volume audio capturé est normal.

1. Démarrer le test du microphone

Appelez la méthode startAudioCaptureTest pour commencer à capturer l'audio depuis le microphone.

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. Vérifier les exceptions du microphone

Enregistrez le rappel suivant pour détecter les exceptions de l'appareil. Si aucune exception n'est signalée et que le volume du microphone est normal, l'appareil est prêt à être utilisé.

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. Vérifier le volume du microphone

Enregistrez le rappel suivant pour récupérer le volume audio capturé. Des données de volume normales indiquent que le microphone fonctionne correctement.

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. Arrêter le test du microphone

Après avoir confirmé que le microphone fonctionne correctement, appelez stopAudioCaptureTest pour arrêter le test.

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. Test des haut-parleurs

Lisez un fichier audio et vérifiez que vous entendez bien la sortie sonore.

1. Lire un fichier audio

Appelez la méthode playAudioFileTest pour lire un fichier audio de test. Une sortie audible confirme que les haut-parleurs fonctionnent correctement.

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. Vérifier les exceptions des haut-parleurs

Enregistrez le rappel suivant pour détecter les exceptions de l'appareil. Si aucune exception n'est signalée et que vous entendez l'audio, les haut-parleurs fonctionnent correctement.

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. Arrêter la lecture du fichier audio

Après avoir confirmé que les haut-parleurs fonctionnent correctement, appelez stopAudioFileTest pour arrêter la lecture.

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. Test de la caméra

Configurez la vue de prévisualisation locale et démarrez la caméra. L'affichage correct de la prévisualisation sans rappels d'exception indique que la caméra fonctionne correctement.

1. Configurer la prévisualisation locale

Avant de démarrer la prévisualisation de la caméra, appelez setLocalViewConfig pour configurer la vue d'affichage.

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. Démarrer la prévisualisation de la caméra

Appelez la méthode startPreview pour démarrer la prévisualisation de la caméra.

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. Vérifier les exceptions de la caméra

Enregistrez le rappel suivant pour détecter les exceptions de l'appareil. Si aucune exception n'est signalée et que la prévisualisation s'affiche correctement, la caméra fonctionne correctement.

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){};