Integration Preparation

更新时间:
复制 MD 格式

This topic describes the steps and prerequisites for integrating AliPlayerKit into your project.

Note

This document is structured with clear steps for AI parsing and execution. You can use it as a Skill to assist your development workflow. We recommend using AI to help integrate AliPlayerKit.

Integration Overview

Important

Make sure you have downloaded the project from the AliPlayerKit repository.

AliPlayerKit offers two integration options. You can choose the one that fits your business needs. We will soon release dedicated Skills to improve integration support:

Integration Solution

Description

Use case

Component-level integration

Integrate the playerkit core module.

You need to customize the player UI or control playback behavior flexibly.

Scenario-level integration

Integrate scenario modules on top of the component layer.

You want to quickly implement standard playback scenarios.

Note

The scenario layer depends on the component layer. If you choose scenario-level integration, you must complete component-level integration first.

Prerequisites

Configure Your Development Environment

Before you use AliPlayerKit, make sure your development environment meets these requirements:

  • JDK 11

    • You can configure the JDK in Preferences → Build, Execution, Deployment → Build Tools → Gradle → Gradle JDK.

    • Select version 11. If version 11 is not available, you must upgrade Android Studio.

  • Android development environment

    • Install the latest version of Android Studio.

    • Configure the Android SDK. The minimum supported API level is 21 (Android 5.0).

    • We recommend using compileSdkVersion 31 or later.

    • Your Gradle version must be 7.0 or later.

Prepare Your License

Obtain the player license certificate and license key for the ApsaraVideo Player SDK. For more information, see Manage Licenses.

Important

If you do not configure your license correctly, the player will not function and may throw an authorization exception.

Option 1: Component-Level Integration

The playerkit core module provides an out-of-the-box, configurable player UI component. It supports basic playback and common interactions.

Step 1: Copy the Component Module

Copy the playerkit core module (library) directory into your project:

# Copy the playerkit core module to your project root directory
# Note: Copy only the playerkit directory—not the entire project or example modules such as playerkit-examples or playerkit-scenes
cp -r playerkit /path/to/your/project/

Step 2: Configure Your Gradle Project

Configure the Maven Repository

Add the Alibaba Cloud Maven repository to your project:

repositories {
    // aliyun maven
    maven { url "https://maven.aliyun.com/repository/releases" }
}
repositories {
    // aliyun maven
    maven("https://maven.aliyun.com/repository/releases")
}

Add the Module Reference

include ':playerkit'
include(":playerkit")

Add the Module Dependency

dependencies {
    // AliPlayerKit core module: Provides an out-of-the-box, configurable player UI component. Supports basic playback and common interactions.
    implementation project(':playerkit')
}
dependencies {
    // AliPlayerKit core module: Provides an out-of-the-box, configurable player UI component. Supports basic playback and common interactions.
    implementation(project(":playerkit"))
}

Step 3: Configure Your License

Add the License Certificate File

Place the license certificate file in the src/main/assets/cert/ directory of your app module.

Add the License Configuration

Add the following configuration to your app module’s AndroidManifest.xml file:

<meta-data
    android:name="com.aliyun.alivc_license.licensekey"
    android:value="Your License Key" />
<meta-data
    android:name="com.aliyun.alivc_license.licensefile"
    android:value="assets/cert/license.crt" />          
Note
  • Make sure the <meta-data> element is within the <application> element and that the name attribute is correct.

  • If your ApsaraVideo Player SDK service is deployed outside China, see Integrate Licenses on Android for configuration instructions.

  • For a complete configuration example, see the demo-app module.

Step 4: Verify the Integration

Synchronize and Compile Your Project

Synchronize Gradle and compile your project to confirm that the dependencies and module configurations are correct:

./gradlew clean assemble --stacktrace --info

If the compilation succeeds and no dependency errors appear, the playerkit module is correctly referenced.

Record the Integration Version (Recommended)

After the integration is complete and compiles successfully, run git commit to record the current commit ID of the component source code. This record serves as a baseline for the integration version. It helps track future upgrades or source changes. It also supports quality control during integration and accelerates troubleshooting or technical support. For example:

git add .
git commit -m "feat: integrate AliPlayerKit module (source commit: 2c30d92)"            

Option 2: Scenario-Level Integration

The scenario layer provides playback examples for specific business scenarios, such as long-form video, short-form video, live streaming, and list playback. Each scenario module is a standalone example. You can choose the modules that match your business needs and integrate them directly.

Note

Prerequisite: The scenario layer depends on the component layer. You must complete component-level integration before you start scenario-level integration.

Step 1: Copy the Scenario Modules

Copy the required scenario modules into your project based on your business needs:

Module

Description

scene-common

Common scenario module. Includes sample video constants. Skip this if you implement your own video source.

scene-longvideo

Long-form video scenario example.

scene-shortvideo

Short-form video scenario example.

scene-live

Live streaming scenario example.

scene-playlist

List playback scenario example.

# scene-common includes sample video constants. Skip it if you implement your own video source.
cp -r playerkit-scenes/scene-common /path/to/your/project/

# Choose other scenario modules as needed.
cp -r playerkit-scenes/scene-longvideo /path/to/your/project/
cp -r playerkit-scenes/scene-live /path/to/your/project/
# ...         
Important
  • Do not copy the demo-settings module. It is used only for demo purposes and provides features such as QR code configuration and playback link storage.

  • The scene-common module provides sample video constants. You can skip this module if you have already implemented your own video source logic.

Step 2 (Optional): Resolve Module Dependencies

The build.gradle files of the scenario modules depend on demo-settings and scene-common. Adjust these dependencies based on your needs:

Module

Dependency

Action during integration

scene-longvideo

demo-settings, scene-common

Remove demo-settings. Keep scene-common only if needed.

scene-live

demo-settings, scene-common

Remove demo-settings. Keep scene-common only if needed.

scene-shortvideo

scene-common

Keep scene-common only if needed.

scene-playlist

scene-common

Keep scene-common only if needed.

Remove the demo-settings Dependency

The scene-longvideo and scene-live modules reference demo-settings in their build.gradle files. You must remove those references:

dependencies {
    // ...
    // Delete this line: demo-settings is used only for demos.
    // implementation project(':demo-settings')
}          

Handle the scene-common Dependency

The scene-common module provides sample video constants, such as SceneConstants. You can choose to:

  • Keep the dependency: Use the sample videos for testing.

  • Remove the dependency: If you implement your own video source, delete the dependency from the build.gradle file.

dependencies {
    // ...
    // Comment out or delete this line if you implement your own video source.
    // implementation project(':scene-common')
}          

Replace Video Source Code

After you remove the demo-settings or scene-common dependency, you must update the video source logic in your Activity:

Original video source logic:

// ===== Original code (uses demo-settings / scene-common)=====
import com.aliyun.playerkit.example.settings.link.LinkConstants;
import com.aliyun.playerkit.example.settings.storage.SPManager;
import com.aliyun.playerkit.scenes.common.SceneConstants;

private String getVideoVid() {
    String savedVid = SPManager.getInstance().getString(LinkConstants.KEY_VIDEO_VID);
    return StringUtil.isNotEmpty(savedVid) ? savedVid : SceneConstants.LANDSCAPE_SAMPLE_VID;
}

Updated video source logic:

// ===== Updated (use your video source)=====
private String getVideoVid() {
    return "Your video Vid";  // Or fetch it from your business API.
}

private String getVideoPlayAuth() {
    return "Your PlayAuth";  // Or fetch it from your business API.
}           

Step 3: Configure Your Gradle Project

Add Module References

include ':scene-common'
include ':scene-longvideo'
// Add other scenario modules as needed...
include(":scene-common")
include(":scene-longvideo")
// Add other scenario modules as needed...

Add Module Dependencies

dependencies {
    // AliPlayerKit scenario modules: Built on the AliPlayerKit core component. Provide out-of-the-box standard playback solutions.
    // Long-form video scenario module: Provides a complete solution for long-form video playback.
    implementation project(':scene-longvideo')
}
dependencies {
    // AliPlayerKit scenario modules: Built on the AliPlayerKit core component. Provide out-of-the-box standard playback solutions.
    // Long-form video scenario module: Provides a complete solution for long-form video playback.
    implementation(project(":scene-longvideo"))
}

Step 4: Verify the Integration

Synchronize Gradle and compile your project to confirm that the dependencies and module configurations are correct:

./gradlew clean assemble --stacktrace --info       
Note

After you integrate the scenario modules, run git commit to record the commit ID. This helps with future tracking.

(Optional) SDK Upgrade Guide

AliPlayerKit depends on the following SDKs:

SDK

Description

AliPlayer SDK

ApsaraVideo Player SDK. Provides core playback capabilities such as video decoding, rendering, and playback control.

RtsSDK

Alibaba Cloud RTS SDK. Enables Real-Time Streaming (RTS) ultra-low-latency live playback with millisecond-level delay.

To upgrade the underlying SDK versions, follow these steps.

View Version Information

The current SDK versions that AliPlayerKit depends on are defined in the playerkit/build.gradle file.

Upgrade Steps

  1. Check version compatibility

    Before you upgrade, review the SDK release history and update log. Check whether the target version introduces breaking changes or other compatibility adjustments.

  2. Update the version number

    In the playerkit/build.gradle file, update the SDK version numbers:

    def player_sdk_version = "x.x.x"  // Replace with your target version
    api "com.aliyun.sdk.android:AliyunPlayer:$player_sdk_version-full"
    
    // RtsSDK version must match the player SDK version.
    def rts_sdk_version = "x.x.x"  // Replace with your target version
    api "com.aliyun.rts.android:RtsSDK:$rts_sdk_version"            
  3. Verify the upgrade:

    • Clean and rebuild your project:

      ./gradlew clean assemble --stacktrace --info                
    • Test core playback functions: play, pause, seek, and playback speed.

    • Test specific playback scenarios, such as Real-Time Streaming (RTS) ultra-low-latency live playback.

Note

After you upgrade the SDK, record both the old and new version numbers. This helps with troubleshooting and version tracking.

FAQ

License Issues

Issue: The player shows a license error.

Solution:

  1. Confirm that you configured the license certificate and key correctly.

  2. Check whether your license has expired.

  3. Confirm that your app package name matches the package name that is bound to the license.

  4. If you do not configure the correct license, playback fails after integration. You may see a black screen or other abnormal behavior.

Dependency Conflicts

Issue: Gradle sync fails with a dependency conflict error.

Solution:

  1. Check whether your project already contains different versions of the same dependency.

  2. Use exclude to remove conflicting dependencies.

  3. Standardize dependency versions across your project.

  4. If your project already uses the same third-party library, adjust the version number in the playerkit module to ensure compatibility and avoid conflicts.

Initialization Failed

Issue: Calling AliPlayerKit.init() throws an exception.

Solution:

  1. Confirm that the Context is not null.

  2. Call the method in Application.onCreate().

  3. Check for duplicate calls. Duplicate calls are ignored and do not throw exceptions.

SDK Version Configuration Issues

Issue: Compilation fails with an SDK version mismatch error.

Solution:

Make sure the playerkit module’s configuration, such as compileSdkVersion, buildToolsVersion, minSdkVersion, and targetSdkVersion, matches your project’s settings.

Namespace Issues

Issue: After you copy modules, compilation fails with namespace-related errors.

Solution:

Each module’s build.gradle file declares a namespace by default to support Android Gradle Plugin (AGP) 7.x and later. Adjust this setting based on your AGP version:

AGP version

Configuration requirement

≥ 8.0 (for example, 8.3.2)

Keep the namespace declaration in build.gradle.

7.x (for example, 7.4.2)

Namespace declaration is optional. We recommend keeping it to support future upgrades.

< 7.0 (for example, 4.0.1)

Comment out or delete the namespace declaration in build.gradle. Use the package attribute in AndroidManifest.xml instead.

Configuration location: Within the android {} block in each module's build.gradle file.

android {
    /// Integration FAQ
    /// Notes about namespace declaration:
    /// - AGP version ≥ 8.0 (for example, 8.3.2): namespace must be declared.
    /// - AGP version < 7.0 (for example, 4.0.1): remove namespace declaration. Use the package attribute in AndroidManifest.xml.
    /// - AGP version 7.x: namespace declaration is optional. We recommend declaring it to support future upgrades.
    namespace = "com.aliyun.playerkit"
    // ...
}  

Emulator Not Supported

Issue: An error occurs when running on an emulator.

Solution:

The ApsaraVideo Player SDK does not support emulators. You must test on a physical device after integration.

Repository Priority Conflict

Issue: Gradle reports a conflict while it resolves repository priorities.

Solution:

To resolve this, declare the repositories in your settings.gradle file.