This topic describes the environment requirements, integration methods, and usage notes of ApsaraVideo Player SDK for Android.
Environment requirements
Item | Description |
Android version | Android 4.3 or later |
Mobile phone processor | One of the following processor architectures must be used:
|
Development tool | We recommend that you use Android Studio. The procedures in this topic are based on Android Studio. To download Android Studio, visit Android Studio. |
Prerequisites
A license for ApsaraVideo Player SDK is registered and the license file
AliVideoCert-********.crt
is obtained. For more information, see Obtain a license.The package for ApsaraVideo Player SDK for Android and the source code of a demo are downloaded. ApsaraVideo Player SDK for Android V5.4.6.0 and later versions provide a demo that does not support AndroidX and a demo that supports AndroidX. We recommend that you download the SDK package and the demo of the latest version based on your business requirements. For more information about the download links, see SDK overview and download.
The following table describes the folders or files in the SDK package after the package is decompressed.
Table 1. Folders or files in the SDK package
Folder or file | Description |
demo | The source code of the demo of ApsaraVideo Player. |
JavaDoc | The API references for ApsaraVideo Player. |
sdk | The Android Archive (AAR) library of ApsaraVideo Player SDK for Android. For more information about the sdk folder, see Files in the sdk folder. |
X.X.XReleaseNote | The release notes of ApsaraVideo Player SDK for Android. |
Table 2. Files in the sdk folder
File | Description |
AliyunPlayer-x.x.x-full.aar | An AAR package that contains FFmpeg. |
AliyunPlayer-x.x.x-part.aar | An AAR package that does not contain FFmpeg. |
AlivcArtp-x.x.x.aar | An AAR package that supports the Alibaba Real-time Transport Protocol (ARTP) protocol. This package is optional. |
AlivcArtc-x.x.x.aar | An AAR package that supports the Alibaba Real-Time Communication (ARTC) protocol. This package is optional. |
If you do not integrate the short video SDK, add the AliyunPlayer-x.xx.x-full.aar dependency to your project.
If you want to integrate the short video SDK for Android and ApsaraVideo Player SDK for Android at the same time, you must add the AliyunPlayer-x.x.x-part.aar dependency for ApsaraVideo Player SDK and the com.aliyun.video.android:AlivcFFmpeg:x.x.x dependency for both ApsaraVideo Player SDK and the short video SDK to your project.
If you include an invalid dependency when you integrate ApsaraVideo Player SDK for Android, an FFmpeg conflict may occur.
limits
ApsaraVideo Player SDK for Android cannot run on simulators. After you integrate ApsaraVideo Player SDK for Android, you must run the SDK on an Android device.
Integrate the SDK by adding local files
The following section describes how to use Android Studio Flamingo | 2022.2.1 to integrate ApsaraVideo Player SDK for Android. You can also follow the procedure to integrate the SDK by using other development tools.
Copy the required AAR package to the libs folder of your project. If the libs folder does not exist, create a libs folder.
In the build.gradle file of the project, add the flatDir setting to the repositories section of the allprojects block. Sample code:
flatDir { dirs 'libs' }
Add the reference to the AAR package and the Conan package to the dependencies block in the build.gradle file of the application. Sample code:
dependencies { implementation fileTree(dir: 'libs', include: ['*.aar']) // You need to add the reference to the Conan package to the dependencies block only for ApsaraVideo Player V5.3.0 and earlier versions. implementation 'com.alivc.conan:AlivcConan:x.x.x' }
Configure obfuscation rules.
Add obfuscation rules to the Proguard-rules.pro file of the application. Sample code:
-keep class com.alivc.**{*;} -keep class com.aliyun.**{*;} -keep class com.cicada.**{*;} -dontwarn com.alivc.** -dontwarn com.aliyun.** -dontwarn com.cicada.**
Integrate the SDK by using Gradle
Make sure that the network is accessible and you can access the Alibaba Cloud Maven repository. If you cannot download the ApsaraVideo Player SDK for Android package from the Maven repository due to a network error, we recommend that you integrate the SDK by adding local files. For more information, see Integrate the SDK by adding local files.
Add the URL of the Alibaba Cloud Maven repository to the build.gradle file of the project. Sample code:
maven { url "https://maven.aliyun.com/repository/releases" }
The following figure shows the result of the preceding operation.
Add dependencies to the dependencies block in the build.gradle file of the application. Sample code:
NoteMake sure that the version number of the SDK is correct. Otherwise, an error is reported and the dependencies fail to be added. For more information about the versions of ApsaraVideo Player SDK for Android, see Release notes for ApsaraVideo Player SDK for Android.
implementation 'com.aliyun.sdk.android:AliyunPlayer:x.x.x-full' // You need to add the reference to Conan package to the dependencies block only for ApsaraVideo Player V5.3.0 and earlier versions. implementation 'com.alivc.conan:AlivcConan:x.x.x'
The following figure shows the result of the preceding operation.
Bind a license to an Android application
Configure a license.
Recommended. Copy the license file to the assets directory of your Android Studio project.
NoteYou can also copy the license file to another directory on your device. If you do so, make sure that the value that corresponds to
com.aliyun.alivc_license.licensefile
for the global environment orcom.aliyun.alivc_license.licensefile_SEA
for the international environment is the same as the path of the license file.Add <meta-data> elements to the AndroidManifest.xml file.
ImportantIf the authentication fails after you configure the license, check whether the <meta-data> elements are added under the <application> element, and whether the names in the <meta-data> elements are correct. If the issue persists, troubleshoot the issue by referring to FAQ about licenses.
If you want to use ApsaraVideo Player SDK V6.14.0 or later on the Alibaba Cloud international site (alibabacloud.com), you must configure a license for the international environment. If you do not use ApsaraVideo Player SDK, you can configure a license for the global environment.
You can bind two licenses to your application at the same time: one for the global environment and one for the international environment. Then, you can specify the environment to use the player by configuring the service environment for ApsaraVideo Player SDK each time you start your application. You cannot switch the environment when the player is running.
// Configure a license for the global environment. This is the default configuration. <meta-data android:name="com.aliyun.alivc_license.licensekey" android:value="foIVziMaUHaRqgDyhf6b6eb8fcf014af39535d0720a32****"/> <!-- TODO: Specify the license key.--> <meta-data android:name="com.aliyun.alivc_license.licensefile" android:value="assets/cert/release.crt"/> <!-- TODO: Specify the path of your license file.--> // Configure a license for the international environment and add _SEA to the end of the license name. <meta-data android:name="com.aliyun.alivc_license.licensekey_SEA" android:value="f6b6foIVziMaUHaRqgDyheb8fcf014af39535d0a32720****"/> <!-- TODO: Specify the license key.--> <meta-data android:name="com.aliyun.alivc_license.licensefile_SEA" android:value="assets/cert/release.crt"/> <!-- TODO: Specify the path of your license file.-->
Configure a service environment for ApsaraVideo Player SDK. This step is required if you use the Alibaba Cloud international site (alibabacloud.com).
ApsaraVideo Player SDK V6.14.0 and later allows you to select a service environment. By default, the global environment is configured for ApsaraVideo Player SDK V6.14.0 and later. Users of the Alibaba Cloud international site (alibabacloud.com) cannot use the global environment. If you want to use the Alibaba Cloud international site (alibabacloud.com), you must update the service environment to the international environment for ApsaraVideo Player SDK by using the following method each time you start your application. Otherwise, authentication will fail for the license that authorizes your application to use ApsaraVideo Player SDK. You can ignore this step in scenarios such as using ApsaraVideo Player SDK of a version that is earlier than V6.14.0 or using other SDKs.
// When you use the Alibaba Cloud international site (alibabacloud.com), make sure that you have updated the service environment before calling an API operation of the player. This ensures that all subsequent services will run on the Alibaba Cloud international site (alibabacloud.com). // Update the service environment to the international environment by calling the following operation. You cannot alter the environment when the player is running. AlivcBase.getEnvironmentManager().setGlobalEnvironment(AlivcEnv.GlobalEnv.ENV_SEA);