All Products
Search
Document Center

LongVideo solution integration for Android

Last Updated: Oct 15, 2019

Environment requirements

The following table lists mandatory requirements.

Name Requirement
Android system version Android 4.0 or later
Android API version API 14 or later
CPU architecture support ARM64 and ARMv7
Integrated tool Android Studio

The following table lists optional requirements that provide reference for developers who compile and run the source code. These requirements are used in the development environment to develop the demo.

Name Requirement
Android Studio version 3.1.3
JRE 1.8.0_152-release-1024-b01 x86_64
JVM OpenJDK 64-Bit
Gradle version gradle-4.4-all
Gradle plug-in version com.android.tools.build:gradle:3.0.1

Demo download

Click SDK download. On the download page, find and download the target source code package in the Download link column of the LongVideo source code table.

Directory structure

Directory structure of the LongVideo source code package

The following table lists the modules contained in the LongVideo source code package.

Name Description
AlivcLongVideo The module that contains the code related to building a LongVideo application.
Aliyunplayer The module that contains the ApsaraVideo Player SDK.
AliyunVideoCommon The public module that contains some utility classes.
thirdparty-lib The module that contains dependent third-party libraries required by the demo.

SDK

The following table lists the AAR packages for the ApsaraVideo Player SDK.

Name Description
AliyunPlayer-xxx-full.aar The AAR package that contains all libraries required by ApsaraVideo Player.
AliyunPlayer-xxx-part.aar The AAR package that contains the core libraries required by ApsaraVideo Player.
If the project only integrates the ApsaraVideo Player SDK, use the AliyunPlayer-xxx-full.aar package. If the project integrates both the short video SDK and the ApsaraVideo Player SDK, use the AliyunPlayer-xxx-part.aar package.
You can also integrate the SDK by using the Gradle package.

implementation 'com.aliyun.sdk.android:AliyunPlayer:4.7.0-part'implementation 'com.aliyun.sdk.android:AliyunPlayer:4.7.0-full'

For more information, see New Player SDK: Integration.

Project compilation

Step 1: Download Gradle

Go to the Gradle official website. On the download page, download the distribution package of Gradle 4.4 required by the compilation environment to a local directory. Then, decompress the downloaded package.Download Gradle

Step 2: Import a project

Open Android Studio. On the homepage, click Open an existing Android Studio project to import the ApsaraLongVideo project from the /demo directory of the downloaded demo.Import a project

Step 3: Configure local Gradle settings
  • Click Cancel to disable the Gradle wrapper.Click Cancel to disable the Gradle wrapper
  • Select the local directory where the Gradle distribution package is decompressed in Step 1 as the directory of the local Gradle distribution.Configure local Gradle settings
Step 4: Compile and run the project

After the compilation, click Run to generate an .apk file and install it on a mobile phone that meets specified hardware requirements.Tips: The demo can run properly on physical devices, but cannot run on virtual machines currently.

Demo integration

Step 1: Copy objects

Copy the objects shown in the following figure to the root directory of the project.Objects that need to be copied

Step 2: Configure Gradle settings

  • Run the following code to configure Gradle settings for the app folder:
  1. buildscript {
  2. repositories {
  3. google()
  4. jcenter()
  5. maven { url "http://maven.aliyun.com/nexus/content/repositories/releases" }
  6. // The maven URL of the project.
  7. maven { url 'http://4thline.org/m2' }
  8. }
  9. apply from: 'thirdparty-lib/config.gradle'
  10. dependencies {
  11. classpath externalAndroidBuildGradlePlugin
  12. }
  13. }
  1. allprojects {
  2. repositories {
  3. google()
  4. jcenter()
  5. maven { url "http://maven.aliyun.com/nexus/content/repositories/releases" }
  6. // The maven URL of the project.
  7. maven { url 'http://4thline.org/m2' }
  8. flatDir { dirs 'src/main/libs' }
  9. }
  10. }
  • Run the following code to download Gradle of a specified version:
  1. distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
  • Add the following code tothe settings.gradle file:
  1. include ':AliyunVideoCommon'
  2. include ':Aliyunplayer:AlivcPlayerTools'
  3. include ':AlivcLongVideo'
  4. include ':AliyunVideoCommon'
  • Run the following code to configure the build.gradle file in the app folder:
  1. implementation project (':AlivcLongVideo')
  2. implementation project (':AliyunVideoCommon')
  3. implementation project (':Aliyunplayer:AlivcPlayerTools')
  4. implementation externalAndroidAppCompatV7
  5. implementation externalAndroidSupportV4
  6. implementation externalAndroidRecyclerView
  7. implementation externalGSON
  8. implementation externalOKHTTP
  9. implementation externalAndroidMultiDex
  • Note: If an error is reported as shown in the following figure, add the packagingOptions configuration code to the build.gradle file in the app folder.
  1. android {
  2. defaultConfig {
  3. ...
  4. }
  5. buildTypes {
  6. ...
  7. }
  8. packagingOptions {
  9. exclude 'META-INF/beans.xml'
  10. }
  11. }

A run error reported after the configuration is completed

Step 3: Add permissions

  1. <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
  2. <uses-permission android:name="android.permission.INTERNET"/>
  3. <uses-permission android:name="android.permission.VIBRATE"/>
  4. <uses-permission android:name="android.permission.RECORD_AUDIO"/>
  5. <uses-permission android:name="android.permission.CAMERA"/>
  6. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
  7. <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
  8. <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
  9. <uses-permission android:name="android.permission.GET_TASKS"/>
  10. <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
  11. <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
  12. <uses-permission android:name="android.permission.WAKE_LOCK"/>
  13. <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
  14. <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
  15. <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
  16. <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
  17. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  18. <uses-permission android:name="android.permission.BLUETOOTH" />
  19. <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
  20. <! --Required for installation with automatic URI update-->
  21. <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />

Step 4: Use the demo

The homepage of the LongVideo application is AlivcHomeActivity. Run the following code to go to the homepage:

  1. Intent intent = new Intent(context,AlivcHomeActivity.class);
  2. context.startActivity(intent);

In the provided LongVideo demo, the GlobalNetConstants class provides the configuration code of some request APIs. You can customize the code as needed, including APIs to request STS information and to play videos.