This document explains how to quickly run the ARTC sample project and experience real-time audio and video features.
Download the sample source code
Alibaba Cloud provides an open source sample project that demonstrates how to use the ARTC SDK APIs. This helps developers understand and integrate the SDK features more intuitively. See the Harmony sample project repository.
Prerequisites
Before running the sample project, ensure your development environment meets the following requirements:
Development tools: DevEco Studio 5.0.3.900 Release or later, along with HarmonyOS NEXT SDK for API Version 12 or later.
Test device: A HarmonyOS device running HarmonyOS NEXT 5.0.0.102 or later (API Version 12 or later) that supports audio and video, with the "Allow debugging" option enabled.
Network environment: Stable network connectivity.
Application preparation: Obtain the AppID and AppKey for your real-time audio and video application. For more information, see Create Application.
Procedure
Step 1: Get the sample project
Clone the ARTC sample project to your local machine:
git clone https://github.com/MediaBox-Demos/amdemos-artc.gitNote: This repository contains sample projects for multiple native platforms using the ARTC SDK. The Harmony platform sample project is located in the Harmony/ARTCExample folder.
The sample project includes client-side code for generating tokens to help you test.
The following shows the file structure of the Harmony/ARTCExample project.
├── Harmony // Root directory for Harmony platform project
│ ├── ARTCExample // Harmony API Example project
│ │ ├── entry // Demo entry project (ArkTS)
│ │ │ ├── src/main/ets
│ │ │ │ ├── common // Common components & utilities
│ │ │ │ │ ├── components // Common UI components (such as title bar)
│ │ │ │ │ ├── keycenter // KeyCenter, encapsulates AppId/AppKey/Token generation
│ │ │ │ │ │ ├── ARTCTokenHelper.ets // Token utility class (configures AppId/AppKey)
│ │ │ │ │ │ └── GlobalConfig.ets // Global configuration singleton
│ │ │ │ │ ├── utils // Permissions, sandbox file management, etc.
│ │ │ │ │ └── ConstantsData.ets / Constants.ets // Constant definitions
│ │ │ │ ├── entryability // Program entry Ability
│ │ │ │ ├── manager // Page stack and navigation management
│ │ │ │ │ └── PageStackCenter.ets // Navigation stack center
│ │ │ │ ├── model // Homepage module configuration
│ │ │ │ │ ├── ModuleInfo.ets // Module info data model
│ │ │ │ │ ├── ModuleManager.ets // Module manager (singleton)
│ │ │ │ │ └── ModuleRegistry.ets // Module registry (controls which features appear on the homepage)
│ │ │ │ └── pages // Business pages
│ │ │ │ ├── Index.ets // Homepage (aggregates module entries)
│ │ │ │ ├── SettingsDialog.ets // Settings dialog (configures AppId/AppKey/UserId)
│ │ │ │ ├── quickstart/ // QuickStart examples
│ │ │ │ │ ├── TokenGenerate.ets // Token generation and channel join
│ │ │ │ │ ├── VideoCall.ets // Video call
│ │ │ │ │ └── VoiceChat.ets // Chat room
│ │ │ │ ├── basicusage/ // Basic feature examples
│ │ │ │ │ ├── VideoBasicUsage.ets // Basic video usage
│ │ │ │ │ ├── AudioBasicUsage.ets // Basic audio usage
│ │ │ │ │ ├── CameraPage.ets // Camera control
│ │ │ │ │ ├── ScreenSharePage.ets // Screen sharing
│ │ │ │ │ ├── SEIPage.ets // SEI signaling
│ │ │ │ │ ├── DataChannelMessagePage.ets // Data channel messages
│ │ │ │ │ ├── PlayAudioFilesPage.ets // Audio file playback
│ │ │ │ │ ├── StreamMonitoringPage.ets // Remote stream monitoring
│ │ │ │ │ └── VoiceChangePage.ets // Voice change/sound effects
│ │ │ │ └── advancedusage/ // Advanced feature examples
│ │ │ │ ├── RecordingPage.ets // Local recording
│ │ │ │ ├── PictureInPicturePage.ets // Picture-in-Picture (PiP)
│ │ │ │ ├── PreJoinChannelTestPage.ets // Pre-join channel test
│ │ │ │ ├── CustomAudioCapturePage.ets // Custom audio capture
│ │ │ │ ├── CustomAudioRenderPage.ets // Custom audio playback
│ │ │ │ ├── CustomVideoCapturePage.ets // Custom video capture
│ │ │ │ ├── CustomVideoRenderPage.ets // Custom video rendering
│ │ │ │ ├── ProcessAudioRawDataPage.ets // Access raw audio data
│ │ │ │ ├── ProcessVideoRawDataPage.ets // Access raw video data
│ │ │ │ ├── HEVCPage.ets // H.265 codec
│ │ │ │ ├── PublishLiveStreamPage.ets // Bypass live streaming
│ │ │ │ ├── LiveLinkMicPage.ets // Co-streaming live broadcast
│ │ │ │ ├── OriginAudioDataWrap.ets // Raw audio data NAPI example
│ │ │ │ ├── OriginVideoDataWrap.ets // Raw video data NAPI example
│ │ │ │ └── pipManager/ // Picture-in-Picture manager
│ │ │ ├── src/main/cpp // Native C++ modules (NAPI)
│ │ │ │ ├── CMakeLists.txt // NAPI build configuration
│ │ │ │ ├── napi_init.cpp // NAPI export entry
│ │ │ │ ├── origin_audio_data.cpp/.h // Raw audio data NAPI interface implementation
│ │ │ │ ├── origin_video_data.cpp/.h // Raw video data NAPI interface implementation
│ │ │ │ └── types/ // Struct definitions used by NAPI
│ │ │ ├── src/main/resources // Resource files (images, strings, etc.)
│ │ │ └── module.json5 // Entry module configuration
│ │ ├── key // Signing certificate
│ │ ├── hvigor/ // Build configuration
│ │ ├── oh-package.json5 // Project dependency declaration
│ │ └── ...
Step 2: Configure the sample project
Open the
Harmony/ARTCExamplefolder in DevEco Studio.Configure the AppID and AppKey for your project: Open the file
Harmony/ARTCExample/entry/src/main/ets/common/keycenter/ARTCTokenHelper.etsand enter the AppID and AppKey obtained from the console.
// Index.ets // Real-time audio and video AppID @Local appId: string = "<real-time audio and video AppID>"; // Real-time audio and video AppKey @Local appKey: string = "<real-time audio and video AppKey>";
Step 3: Compile and run the sample project
Connect your HarmonyOS development device. In DevEco Studio, select your device from the device dropdown in the toolbar, then choose the entry module from the adjacent module selector.
Set up automatic signing for the project.
Choose
File -> Project Structure -> Signing Configs. In the window that appears, clickAutomatically generate signature. After automatic signing completes, click OK.If you have not signed in before, click
Sign Inin the prompt and log on with your Huawei account.In DevEco Studio, click Run to compile and run the project. After successful compilation, the
ARTCExampleapp installs on your device.