This guide describes how to integrate the short-form drama solution into an Android project.
Source code
Download source code
The demo source code for this solution is open source. You can download the complete source code from Demo Experience. We recommend using a Professional Edition license for the best experience.
Environment requirements
Category | Requirement | ||||||
Development environment | Android Studio 4.0 or later is recommended. | ||||||
System version | Android 5.0 (API Level 21) or later. | ||||||
Other | A physical device that runs Android 5.0 or later. Debugging on emulators is not supported. | ||||||
Prerequisites
You have obtained an ApsaraVideo Player SDK license and License Key. To associate the license with your application, see Associate a license.
In the VOD console, go to SDK Management > My Licenses in the left-side navigation pane. On the License Management tab, click Download Certificate below your application name to obtain the license file.
Run the demo
After downloading the demo source code, open the project in Android Studio.
Place the license certificate in the
src/main/assetsdirectory of yourAndroid Studioproject.Add the <meta-data> node to the AndroidManifest.xml file.
ImportantThe <meta-data> node must be placed inside the <application> element. If license verification fails after configuration, ensure the <meta-data> node is correctly placed and its key/value pairs are correct.
<meta-data android:name="com.aliyun.alivc_license.licensekey" android:value="no80rm6m8ayTXNTk80637a6cdef2a4825****************" /> <!--TODO: Set your LicenseKey. For more information, see the console.--> <meta-data android:name="com.aliyun.alivc_license.licensefile" android:value="assets/cert/license.crt" /> <!--TODO: Set your LicenseFile to enable ApsaraVideo Player SDK verification.-->Test on a physical device
Connect a physical Android device. In the Android Studio toolbar, select your connected device from the device selection dropdown menu.
Click the Run button (the green triangle icon) in the Android Studio toolbar to build the project and deploy the application to your physical device.
After installation, run the short-form drama application on your device.
The AUIShortVideoList component is designed to work with VodAppServer, the management backend for Alibaba Cloud VOD short-form dramas. It provides content management, playback distribution, and authentication control.
This client-server collaboration enables end-to-end capabilities, allowing you to quickly build a short-form drama service without developing your own backend. This significantly reduces costs and ensures a consistent experience between the frontend and backend.
Component integration
The following sections explain how to use the AUIShortVideoList component and its public APIs to implement video list playback.
Preparation
Integrate the ApsaraVideo Player SDK license.
For more information, see Integrate a license.
Copy the AUIShortVideoList module to your project directory.
In your project's gradle file, add Alibaba Cloud's Maven repository to the repositories block.
Add the following content to the settings.gradle file in your project's root directory:
Groovy DSL
repositories { // aliyun maven maven { url "https://maven.aliyun.com/repository/releases" } }Kotlin DSL
repositories { // aliyun maven maven("https://maven.aliyun.com/repository/releases") }Add the module reference and dependency.
To add a module reference, add the following content to the settings.gradle file in the project's root directory:
Groovy DSL
// If the AUIShortVideoList module is in the AUIPlayerKits folder: include ':AUIPlayerKits:AUIShortVideoList' // If the AUIShortVideoList module is in the project's root directory: include ':AUIShortVideoList'Kotlin DSL
// If the AUIShortVideoList module is in the AUIPlayerKits folder: include(":AUIPlayerKits:AUIShortVideoList") // If the AUIShortVideoList module is in the project's root directory: include(":AUIShortVideoList")To add a module dependency, add the following content to the build.gradle file of the app module:
Groovy DSL
// If the AUIShortVideoList module is in the AUIPlayerKits folder: implementation project(':AUIPlayerKits:AUIShortVideoList') // If the AUIShortVideoList module is in the project's root directory: implementation project(':AUIShortVideoList')Kotlin DSL
// If the AUIShortVideoList module is in the AUIPlayerKits folder: implementation(project(":AUIPlayerKits:AUIShortVideoList")) // If the AUIShortVideoList module is in the project's root directory: implementation(project(":AUIShortVideoList"))
Build and run the project to ensure the component is integrated correctly.
NoteAfter the integration is complete, we recommend that you run a
git committo record the latest commit ID of the current component. This provides an important reference for tracking future component updates, records the code differences before and after an update, and helps you ensure integration quality. It also allows you to quickly identify the component version when you seek technical support, thereby improving support efficiency.For integration issues, see Integration FAQ.
After preparing the AUIShortVideoList component for integration, you can copy the following code into your project.
Usage
You can use the AUIShortVideoList component in one of the following three ways to implement its functionality:
AUIShortVideoListActivity
You can start this Activity directly. See the example below for the call logic. To get the
videoInfoListJSONdata, see Retrieve data.Java
// TODO: context is android context Intent intent = new Intent(context, AUIShortVideoListActivity.class); // TODO: videoInfoListJSON is the serialized string of List<VideoInfo> intent.putExtra(AUIShortVideoListView.KEY_VIDEO_INFO_LIST_DATA, videoInfoListJSON); startActivity(intent);Kotlin
// TODO: context is android context val intent = Intent(context, AUIShortVideoListActivity::class.java) // TODO: videoInfoListJSON is the serialized string of List<VideoInfo> intent.putExtra(AUIShortVideoListView.KEY_VIDEO_INFO_LIST_DATA, videoInfoListJSON) startActivity(intent)AUIShortVideoListFragment
You can embed this Fragment in your Activity or another Fragment. See the example below for the call logic:
In your XML layout, add a FrameLayout to host the Fragment:
<FrameLayout android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" />Initialize the Fragment and add it to the container.
Java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState == null) { AUIShortVideoListFragment fragment = new AUIShortVideoListFragment(); Bundle bundle = new Bundle(); // TODO: videoInfoListJSON is the serialized string of List<VideoInfo> bundle.putString(AUIShortVideoListView.KEY_VIDEO_INFO_LIST_DATA, videoInfoListJSON); fragment.setArguments(bundle); getSupportFragmentManager() .beginTransaction() .replace(R.id.fragment_container, fragment) .commit(); } }Kotlin
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) if (savedInstanceState == null) { val fragment = AUIShortVideoListFragment() val bundle = Bundle() // TODO: videoInfoListJSON is the serialized string of List<VideoInfo> bundle.putString(AUIShortVideoListView.KEY_VIDEO_INFO_LIST_DATA, videoInfoListJSON) fragment.arguments = bundle supportFragmentManager .beginTransaction() .replace(R.id.fragment_container, fragment) .commit() } }
AUIShortVideoListView
You can use this View component to build an immersive list playback page. For the specific call logic, see the following example:
Add the View component to your XML layout:
<!-- 1. Add Short Video List View Component --> <com.alivc.player.playerkits.shortvideolist.AUIShortVideoListView android:id="@+id/aui_video_list_view" android:layout_width="match_parent" android:layout_height="match_parent" />In your code, declare the short video list playback View component and add the
List<VideoInfo>data source.Java
// 2. Declaration of Short Video List View private AUIShortVideoListView mShortVideoListView; mShortVideoListView = findViewById(R.id.aui_video_list_view); // 3. TODO: Retrieve data and fill it into videoInfoList List<VideoInfo> videoInfoList; // 4. Add List<VideoInfo> type data source to Short Video List View mShortVideoListView.addSources(videoInfoList); // mShortVideoListView.loadSources(videoInfoList);Kotlin
// 2. Declaration of Short Video List View private lateinit var mShortVideoListView: AUIShortVideoListView mShortVideoListView = findViewById(R.id.aui_video_list_view) // 3. TODO: Retrieve data and fill it into videoInfoList val videoInfoList: List<VideoInfo> // 4. Add List<VideoInfo> type data source to Short Video List View mShortVideoListView.addSources(videoInfoList) // mShortVideoListView.loadSources(videoInfoList)
Retrieve data
The AUIShortVideoList component uses the List<VideoInfo> data structure, where VideoInfo is a data class that stores video information. Its data structure is as follows:
Field | Type | Description | Notes |
id | int | Unique video ID | Used to uniquely identify each video. |
url | String | Video source URL | Can be any supported video format, such as MP4 or M3U8. |
coverUrl | String | Video thumbnail URL | |
author | String | Video author | |
title | String | Video title | |
type | String | Video type | Corresponds to the VideoType enum, e.g., video or ad. |
To ensure that the AUIShortVideoList component works properly, pass the serialized List<VideoInfo> string through a Bundle. The following is sample code:
intent.putExtra(AUIShortVideoListView.KEY_VIDEO_INFO_LIST_DATA, videoInfoListJSON);You can use network requests or data conversion to obtain the final List<VideoInfo> data source and serialize it into a JSON string. The following is an example:
Network request
Java
AUIShortVideoListUtil.requestVideoInfoList(new AUIShortVideoListUtil.OnNetworkCallBack<List<VideoInfo>>() { @Override public void onResponse(List<VideoInfo> videoInfoList) { if (videoInfoList == null || videoInfoList.isEmpty()) { // TODO: Request video info list error! return; } String videoInfoListJSON = AUIShortVideoListUtil.serializeVideoInfoListToJson(videoInfoList); // TODO: Use videoInfoList or videoInfoListJSON... } });Kotlin
AUIShortVideoListUtil.requestVideoInfoList(object : AUIShortVideoListUtil.OnNetworkCallBack<List<VideoInfo?>?> { override fun onResponse(videoInfoList: List<VideoInfo?>?) { if (videoInfoList.isNullOrEmpty()) { // TODO: Request video info list error! return } val videoInfoListJSON = AUIShortVideoListUtil.serializeVideoInfoListToJson(videoInfoList) // TODO: Use videoInfoList or videoInfoListJSON... } })Data conversion
Java
ArrayList<VideoInfo> videoInfoList = AUIShortVideoListUtil.assembleVideoInfoList(); if (videoInfoList == null || videoInfoList.isEmpty()) { // TODO: Assemble video info list error! return; } String videoInfoListJSON = AUIShortVideoListUtil.serializeVideoInfoListToJson(videoInfoList); // TODO: Use videoInfoList or videoInfoListJSON...Kotlin
val videoInfoList = AUIShortVideoListUtil.assembleVideoInfoList() if (videoInfoList.isNullOrEmpty()) { // TODO: Assemble video info list error! return } val videoInfoListJSON = AUIShortVideoListUtil.serializeVideoInfoListToJson(videoInfoList) // TODO: Use videoInfoList or videoInfoListJSON...
Integration FAQ
Black screen or other playback issues
Check your ApsaraVideo Player SDK license configuration. For more information, see Integrate a license.
Compilation or runtime errors
Ensure the module's compileSdkVersion, buildToolsVersion, minSdkVersion, and targetSdkVersion match your main project's settings.
If your project already contains the same third-party library, adjust the version number in the module to ensure compatibility and avoid conflicts.
Playback fails on an emulator
The ApsaraVideo Player SDK does not support emulators. Test on a physical device after integration.
Error: "Namespace not specified"
Check your Android Gradle Plugin (AGP) version. If you use a later version, such as 8.3.2, you must manually add the namespace setting in each module's build.gradle file. In earlier AGP versions, this was configured in the package attribute of the module's /src/main/res/AndroidManifest.xml file.
Gradle repository priority conflict
Declare the repository in the settings.gradle file first to give it priority.
Use cases
The AUIShortVideoList component supports low-code integration for various use cases. You can build on this component to create features for specific scenarios. See the examples in AUIPlayerScenes, such as AUIShortDramaList (short-form drama theater module) and AUIShortDramaFeeds (short-form drama feeds stream module).
Short-form drama theater
Overview
AUIShortDramaList is a scenario-specific module built on the AUIShortVideoList component. It provides a theater detail page and a recommendations page, supporting nested two-level navigation and shared player instances.
Integration
Before building the short-form drama theater use case, ensure that you have completed the integration preparation for the AUIShortVideoList component.
Copy the AUIShortDramaList module to your project.
Check the dependencies of the AUIShortVideoList component, and add the module reference and dependency.
Check the component dependency. In the build.gradle file of the AUIShortDramaList module, verify that the dependency on AUIShortVideoList is configured.
// If the AUIShortVideoList module is in the AUIPlayerKits folder: implementation project(':AUIPlayerKits:AUIShortVideoList') // If the AUIShortVideoList module is in the project's root directory: implementation project(':AUIShortVideoList')Add the module reference to your root settings.gradle file.
Groovy DSL
// If the AUIShortDramaList module is in the AUIPlayerScenes folder: include ':AUIPlayerScenes:AUIShortDramaList' // If the AUIShortDramaList module is in the project's root directory: include ':AUIShortDramaList'Kotlin DSL
// If the AUIShortDramaList module is in the AUIPlayerScenes folder: include(":AUIPlayerScenes:AUIShortDramaList") // If the AUIShortDramaList module is in the project's root directory: include(":AUIShortDramaList")Add the module dependency to your app's build.gradle file.
Groovy DSL
// If the AUIShortDramaList module is in the AUIPlayerScenes folder: implementation project(':AUIPlayerScenes:AUIShortDramaList') // If the AUIShortDramaList module is in the project's root directory: implementation project(':AUIShortDramaList')Kotlin DSL
// If the AUIShortDramaList module is in the AUIPlayerScenes folder: implementation(project(":AUIPlayerScenes:AUIShortDramaList")) // If the AUIShortDramaList module is in the project's root directory: implementation(project(":AUIShortDramaList"))
Build and run the project to ensure correct integration.
Usage
You can start the short-form drama theater Activity directly, as shown below.
Java
// TODO: context is android context
Intent intent = new Intent(context, AUIShortDramaListActivity.class);
startActivity(intent);Kotlin
// TODO: context is android context
val intent = Intent(context, AUIShortDramaListActivity::class.java)
startActivity(intent)Retrieve data
The AUIShortDramaList module uses the List<PlaylistInfo> data structure. PlaylistInfo is a data class for storing short drama series, and its data structure is as follows:
Field | Type | Description | Notes |
playlistId | String | Unique series ID | Uniquely identifies a short-form drama resource. |
playlistName | String | Series name | The official name of the short-form drama displayed in the UI. |
playlistDescription | String | Series list description | The description of the list displayed in the UI. |
playlistStatus | String | List status | Used to handle the status of the list. |
playlistTags | String | List tags | Tags for different lists displayed in the UI. |
playlistCoverUrl | String | Series cover image | The cover image displayed on the list or details page. |
playlistOrderBy | String | Sort order | asc (ascending, default) or desc (descending). |
playlistExtension | String | List extension | User-defined, can be null. |
createTime | String | List creation time | Automatically generated upon creation. |
modifyTime | String | Last modification time of the list | Automatically generated upon modification. |
requestId | String | Request ID | Used for troubleshooting this API call. |
playlistVideos | VideoInfo | Video list | The list of videos included in this playlist. |
You can obtain the final List<PlaylistInfo> data source through network requests or data transformation:
Network request
Java
AUIShortDramaListUtil.requestPlaylistInfoList(requestParams, new AUIShortVideoListUtil.OnNetworkCallBack<List<PlaylistInfo>>() { @Override public void onResponse (List <PlaylistInfo> playlist) { if (playlist == null || playlist.isEmpty()) { // TODO: Request playlist info list error! return; } // TODO: Use PlaylistInfoList } });Kotlin
AUIShortDramaListUtil.requestPlaylistInfoList(object : AUIShortVideoListUtil.OnNetworkCallBack<List<PlaylistInfo?>?> { override fun onResponse(playlist: List<PlaylistInfo?>?) { if (playlist.isNullOrEmpty()) { // TODO: Request playlist info list error! return } // TODO: Use PlaylistInfoList } })Data conversion
Java
ArrayList<PlaylistInfo> playlist = AUIShortDramaListUtil.assemblePlayListInfoList(); if(playlist ==null || playlist.isEmpty()) { // TODO: Assemble playlist info list error! return; } // TODO: Use PlaylistInfoListKotlin
val playlist = AUIShortDramaListUtil.assemblePlayListInfoList() if (playlist.isNullOrEmpty()) { // TODO: Assemble playlist info list error! return } // TODO: Use PlaylistInfoList
Short-form drama feeds stream
Overview
AUIShortDramaFeeds is a scenario-specific module for a short-form drama feeds stream, built on the AUIShortVideoList component. It provides a tabbed feeds interface that supports nested tabs, up/down/left/right swipe gestures for playback, and shared player instances.
Integration
Before building the short-form drama feeds stream use case, ensure that you have completed the integration preparation for the AUIShortVideoList component.
Copy the AUIShortDramaFeeds module to your project.
Check the dependencies of the AUIShortVideoList component, and add the module reference and dependency.
Check the component dependency. In the build.gradle file of the AUIShortDramaFeeds module, verify that the dependency on AUIShortVideoList is configured.
// If the AUIShortVideoList module is in the AUIPlayerKits folder: implementation project(':AUIPlayerKits:AUIShortVideoList') // If the AUIShortVideoList module is in the project's root directory: implementation project(':AUIShortVideoList')Add the module reference to your root settings.gradle file:
Groovy DSL
// If the AUIShortDramaFeeds module is in the AUIPlayerScenes folder: include ':AUIPlayerScenes:AUIShortDramaFeeds' // If the AUIShortDramaFeeds module is in the project's root directory: include ':AUIShortDramaFeeds'Kotlin DSL
// If the AUIShortDramaFeeds module is in the AUIPlayerScenes folder: include(":AUIPlayerScenes:AUIShortDramaFeeds") // If the AUIShortDramaFeeds module is in the project's root directory: include(":AUIShortDramaFeeds")Add the module dependency to your app's build.gradle file:
Groovy DSL
// If the AUIShortDramaFeeds module is in the AUIPlayerScenes folder: implementation project(':AUIPlayerScenes:AUIShortDramaFeeds') // If the AUIShortDramaFeeds module is in the project's root directory: implementation project(':AUIShortDramaFeeds')Kotlin DSL
// If the AUIShortDramaFeeds module is in the AUIPlayerScenes folder: implementation(project(":AUIPlayerScenes:AUIShortDramaFeeds")) // If the AUIShortDramaFeeds module is in the project's root directory: implementation(project(":AUIShortDramaFeeds"))
Build and run the project to ensure the component is integrated correctly.
Usage
You can start the short-form drama feeds stream Activity directly. Refer to the example below.
Java
// TODO: context is android context
Intent intent = new Intent(context, AUIShortDramaFeedsActivity.class);
startActivity(intent);Kotlin
// TODO: context is android context
val intent = Intent(context, AUIShortDramaFeedsActivity::class.java)
startActivity(intent)Retrieve data
The AUIShortDramaFeeds module uses the List<VideoInfo> data structure, where VideoInfo is the data class that stores video information. For more information, see the documentation for the AUIShortVideoList component.
Core features
This component uses the ApsaraVideo Player SDK, leveraging multiple player instances (AliPlayer), preloading (MediaLoader), and pre-rendering. It incorporates core capabilities such as preloading, pre-rendering, HTTPDNS, and encrypted playback to enhance the viewing experience by reducing latency and improving stability and security. For more details, see Advanced features.
Preloading
By using a sliding window strategy, the component dynamically starts and stops video preloading tasks. The underlying SDK intelligently adjusts task priority based on network conditions to ensure the current and upcoming videos receive more network resources. This significantly improves start-up speed and reduces buffering, providing a smooth experience even when scrolling quickly. For more information, see Preloading.
Pre-rendering
The component pre-renders the first frame of upcoming videos in the background, reducing black screens and creating a seamless playback experience. The ApsaraVideo Player SDK has supported pre-rendering since v6.16.0. For more information, see Pre-rendering.
Multi-instance player pool
This solution implements a globally shared, configurable player instance pool. Through optimized API calls and resource management, it improves performance and efficiency in thread management, CPU utilization, and memory usage. This optimization reduces lag during scrolling, making the playback experience smoother.
Picture-in-Picture (PiP) with auto-play
Using an independent player instance for the floating window ensures continuous rendering when switching episodes. This achieves a seamless and non-disruptive viewing experience. This implementation follows best practices for Picture-in-Picture (PiP) playback.
HTTPDNS
HTTPDNS provides faster and more stable DNS resolution. By replacing traditional DNS, it reduces lookup times, improving video loading speed and stability. Since v6.12.0, HTTPDNS is enabled by default in the ApsaraVideo Player SDK. For more information, see HTTPDNS.
Video encryption
Short-form dramas are typically 1- to 3-minute MP4 videos. The ApsaraVideo Player SDK has supported proprietary encryption for MP4 playback since v6.8.0, providing robust security for your content. For more information, see How to play encrypted videos.
To play a video that uses proprietary encryption, the following conditions must be met:
When you pass a proprietarily encrypted MP4 video to a player, your application must append
etavirp_nuyila=1to the video URL. For example, if the original video URL ishttps://example.aliyundoc.com/test.mp4, the URL that you must pass to the player ishttps://example.aliyundoc.com/test.mp4?etavirp_nuyila=1.The UID associated with your app's license must match the UID used to encrypt the MP4 video.
To verify that a video uses proprietary encryption, check for the following:
The metadata must contain the
AliyunPrivateKeyUritag.The video cannot be played directly with ffplay.
H.265 adaptive playback
If hardware decoding of an H.265 stream fails and an H.264 backup stream is available, the player automatically switches to the H.264 stream. If no backup stream is available, it falls back to H.265 software decoding. For more information, see H.265 adaptive playback.
Adaptive bitrate (ABR) streaming
The ApsaraVideo Player SDK supports multi-bitrate adaptive HLS and DASH video streams. You can call the selectTrack method of the player to switch the playback bitrate, which enables adaptive video quality switching based on network conditions. For more information, see Network-adaptive switching.
Screen recording prevention
This feature protects your video content by monitoring for screen recording and screenshot actions and stopping playback if they are detected. This effectively prevents unauthorized recording and distribution.
// Android-specific feature to prevent screen recording and screenshots in the app
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);