The demo of ApsaraVideo Player SDK for Android contains the sample code for the common
features of ApsaraVideo Player SDK for Android. Before you integrate ApsaraVideo Player
SDK for Android, you can run the demo to understand and experience the features of
ApsaraVideo Player SDK for Android. You can use ApsaraVideo Player SDK for Android
by importing the complete demo without the need to separately integrate SDKs. Alternatively,
you can import specific modules in the demo as needed.
Demo of ApsaraVideo cloud-device integration solution
The demo of ApsaraVideo cloud-device integration solution provides complete service-level
user interfaces (UIs) and business source code. The demo of ApsaraVideo cloud-device
integration solution contains the short video SDK, ApsaraVideo Player SDK, and the
upload SDK. You can scan a QR code and download the demo app to experience the features
of ApsaraVideo Player. For more information about the QR code, see
Demo. You can also use the demo of ApsaraVideo Player SDK for Android for free. The demo
of ApsaraVideo Player SDK for Android provides built-in UIs. The following table and
sections describe the scenarios and procedures for integrating the demo with and without
the built-in UIs.
Scenario |
Description |
Integrate the complete demo (with the built-in UIs) |
Applicable to a scenario in which you need the built-in UIs and want to use all the
features provided by the demo.
In this scenario, you can import the complete demo and run it without the need to
separately integrate SDKs.
|
Integrate specific modules in the demo (with the built-in UIs) |
Applicable to a scenario in which you need the built-in UIs but want to use only specific
features provided by the demo.
In this scenario, you can import specific modules in the demo based on your requirements
without the need to separately integrate SDKs.
|
Integrate the demo (without the built-in UIs) |
Applicable to a scenario in which you do not need the built-in UIs but want to use
all the features provided by the demo because you have custom UIs or need no UI at
all.
In this scenario, you must first integrate SDKs and then import the relevant files
in the demo.
|
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
The ApsaraVideo Player SDK package for Android is downloaded. The package contains
ApsaraVideo Player SDK for Android and the demo. We recommend that you download the
latest version. For more information about the download link, see SDK download.
After you decompress the package, the following directory structure appears.
Table 1. Directory structure
Folder |
Description |
demo |
The demo of ApsaraVideo Player. For more information about the directory structure
of the demo, see the Table 2 table in this topic.
|
JavaDoc |
The API reference of ApsaraVideo Player. |
sdk |
The .aar library of ApsaraVideo Player SDK for Android. |
X.X.XReleaseNote |
The release notes. |
Table 2. Directory structure of the demo for Android
Module |
Description |
AliyunListPlayer |
The list playback module, which contains the sample code of the list player. |
AliyunLiveShiftPlayer |
The time shifting module, which contains the sample code of the time shifting feature.
|
AliyunPlayer |
The ApsaraVideo Player module, which contains the sample code of ApsaraVideo Player.
|
AliyunPlayerBase |
The base module of the ApsaraVideo Player demo. This module integrates ApsaraVideo
Player SDK for Android by using Gradle.
Note You must import this module, regardless of which module related to ApsaraVideo Player
in the demo is imported.
|
AliyunVideoCommon |
The common module for Alibaba Cloud projects, which contains specific utility classes.
Note You must import this module, regardless of which module related to ApsaraVideo Player
in the demo is imported.
|
zxing |
The QR code scanning module. |
thirdparty-lib |
The module that contains all dependencies required by the demo.
Note You must import the thirdparty-lib module. The thirdparty-lib module is not a built-in
module in Android Studio. Therefore, you must copy the module to the directory that
stores the AliyunPlayerBase and AliyunVideoCommon modules in your project.
|
Integrate the complete demo (with the built-in UIs)
After you import the complete demo of ApsaraVideo Player SDK for Android, you can
use the features of ApsaraVideo Player without the need to separately integrate SDKs.
In the navigation bar of Android Studio, choose . Import the demo of ApsaraVideo Player, as shown in the following figure.
Integrate specific modules in the demo (with the built-in UIs)
You can import specific modules in the demo of ApsaraVideo Player SDK for Android
to use specific features and the built-in UIs of ApsaraVideo Player. In this case,
you do not need to separately integrate SDKs.
Note The following example shows you how to import the AliyunPlayer module of the demo.
- In the navigation bar of Android Studio, choose . Select the player_demo module.
Note You must import the AliyunPlayerBase, AliyunVideoCommon, and thirdparty-lib modules.
You can also import other modules as needed. For more information, see
Table 2.
- Click Finish. Android Studio automatically selects other required modules, as shown in the following
figure.
- After the modules are imported, copy the thirdparty-lib module to your project and
add the reference to the module and the URL of the Alibaba Cloud Maven repository
to the build.gradle file of the project.
buildscript {
apply from: 'thirdparty-lib/config.gradle'
repositories {
google()
jcenter()
maven { url "http://maven.aliyun.com/nexus/content/repositories/releases" }
// The URL of the Maven repository that is required for screen mirroring.
maven { url 'http://4thline.org/m2' }
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "http://maven.aliyun.com/nexus/content/repositories/releases" }
// The URL of the Maven repository that is required for screen mirroring.
maven { url 'http://4thline.org/m2' }
}
}
- Open the build.gradle file in the app directory and change the values of the compileSdkVersion,
buildToolsVersion, minSdkVersion, and targetSdkVersion parameters to the values provided
in the thirdparty-lib/config.gradle file in the Module directory of the demo.
If the error in the following figure appears, see the
Troubleshooting section in this topic troubleshoot the error.
- In the build.gradle file of the app directory, remove the AndroidX-related dependencies
and add the following dependencies:
implementation externalAndroidSupportV4
implementation externalAndroidAppCompatV7
implementation project(':Aliyunplayer:player_demo')
After integration, you can run the following code to use the AliyunPlayer module of
ApsaraVideo Player:
Intent intent = new Intent(MainActivity.this,AliyunPlayerSettingActivity.class);
startActivity(intent);
Integrate the demo (without the built-in UIs)
The demo provides a variety of built-in UIs. However, you may have custom UIs or require
no UI at all. In this case, you can perform the following steps to use only the features
provided by the demo:
- Integrate ApsaraVideo Player SDK for Android.
- Copy specific code in the demo.
Copy the AliyunRenderView, IRenderView, TextureRenderView, and SurfaceRenderView files
in the
Aliyunplayer/AlivcPlayerTools/src/main/java/com/aliyun/player/alivecpalyerexpand/widget directory.
Note
- The AliyunRenderView file is used to encapsulate the player and bind the player with
the render view.
- The IRenderView file defines the basic rendering interface. Both SurfaceRenderView
and TextureRenderView are implemented based on IRenderView.
- The SurfaceRenderView file is used to render video images based on the SurfaceView
class. The TextureRenderView file is used to render video images based on the TextureView
class.
- You do not need to copy the AliyunVodPlayerView file because this file contains the
sample code of the AliyunRenderView class.
- Use the AliyunRenderView class.
For more information, see the sample code in the AliyunVodPlayerView file.
- Create an AliyunRenderView object.
<?xml version="1.0" encoding="utf-8"?>
<!-- LinearLayout is the root view group in this example. You can use other view groups as needed. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<! -- The custom view of the player, which encapsulates the player and the render view. Parameters:
The android:id parameter specifies the view ID. Set this parameter to the actual value.
The android:layout_width parameter specifies the width of the view. You can change the value, but the value change may affect the playback image.
The android:layout_height parameter specifies the height of the view. You can change the value, but the value change may affect the playback image. -->
<com.aliyun.playertest.playerDemo.AliyunRenderView
android:id="@+id/aliyunRenderView"
android:layout_width="match_parent"
android:layout_height="200dp" />
</LinearLayout>
- Call the methods of the AliyunRenderView class.
java
// The method that can be called to specify the type of the render view. You can set the type to SurfaceType.TEXTURE_VIEW or SurfaceType.SURFACE_VIEW.
aliyunRenderView.setSurfaceType(AliyunRenderView.SurfaceType.SURFACE_VIEW);
// The method that can be called to set listeners.
aliyunRenderView.setXXXListener;
// The method that can be called to configure the playback source. The setDataSource method is a reload method. You can call this method to configure playback sources such as sts and playAuth.
aliyunRenderView.setDataSource(urlSource);
// The playback-related methods.
aliyunRenderView.prepare();
aliyunRenderView.start()
aliyunRenderView.pause()
aliyunRenderView.stop()
aliyunRenderView.release()
Note The preceding code shows specific methods of the AliyunRenderView class. You can call
other methods of the AliyunRenderView class based on the sample code of the AliyunVodPlayerView
class. You can also call other methods of the AliyunRenderView class based on the
API reference of ApsaraVideo Player SDK for Android.
Troubleshooting
If the error in the following figure appears when you use the built-in UIs and specific
features provided by the demo of ApsaraVideo Player, perform the following steps for
troubleshooting:
- Open the app/AndroidManifest.xml file and add the following code to the application tag:
android:allowBackup="true"
- Open the values/themes.xml and values-night/themes.xml files and change the value of android:theme to @style/Theme.AppCompat.NoActionBar.