All Products
Search
Document Center

ApsaraVideo VOD:Integrate the short video SDK for Android

Last Updated:Sep 16, 2022

This topic describes how to integrate the short video SDK for Android and provides the relevant API references.

Prerequisites

The development environment is set up. The following table describes the requirements for the development environment.

Environment

Description

Android

Android 4.3 or later.

Java

Java 1.7 or later.

API LEVEL

Android API level 18 or later.

Android Studio

Android Studio 2.3 or later. Visit Android Studio to download Android Studio.

(Recommended) Integrate the SDK by using Maven dependencies

  1. Add the Alibaba Cloud Maven repository.

    Add the URL of the Alibaba Cloud Maven repository to the build.gradle file in your project.

    allprojects {
        repositories {
            maven {
                url 'http://maven.aliyun.com/nexus/content/repositories/releases/'
           }
        }
    }
  2. On theAdd dependencies to the Maven project..

    dependencies{
        implementation 'com.aliyun.video.android:svideopro:3.34.0' // Required dependency for the short video SDK Professional Edition. 
        implementation 'com.aliyun.video.android:core:1.2.2' // Required dependency for the core library. 
        // AlivcFFmpeg V4.3.0 or later must be used. Select one of the following versions. 
        implementation 'com.aliyun.video.android:AlivcFFmpeg:4.3.2.0-part' // Dedicated dependency for the short video SDK, which has a small package size. 
        implementation 'com.aliyun.video.android:AlivcFFmpeg:4.3.2' // Dependency that is used by both the short video SDK and ApsaraVideo Player SDK. If you are integrating both the short video SDK and ApsaraVideo Player SDK, use the version provided in this code block. 
        implementation 'com.aliyun.video.android:upload:1.6.6' // Optional dependency for an upload library. 
        implementation 'com.google.code.gson:gson:2.8.0' // Dependency for a third-party library. 
        implementation 'com.squareup.okhttp3:okhttp:3.2.0' // Dependency for a third-party library. 
        implementation 'com.aliyun.dpa:oss-android-sdk:+'// The upload of short videos depends on the upload SDK and OSS. 
    }

Note

The short video SDK supports only the armeabi-v7a and arm64-v8a instruction sets. To ensure compatibility with armeabi, copy the .so files in the armeabi-v7a folder to the armeabi folder. The short video SDK is applicable only to Android 4.3 or later, and compatibility for ARMv5 and ARMv6 devices is not required.

Manually integrate the SDK

Import AAR packages

  1. Create a module.

    In Android Studio, choose File > New > New Module to create a library module. In this example, the library module is named AliyunSvideoLibrary.

    SDK_1
  2. Copy AliyunSdk-RCE.aar, AlivcConan-x.x.x.aar, and AlivcCore.jar from the SDK directory to the created module and add the module to your project.

    SDK_2
  3. Add AAR and JAR packages by using Gradle.

    dependencies {
     implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs')
    }
  4. Add the dependency of the AliyunSvideoLibrary module to the app module.

     dependencies {
        implementation project(":AliyunSvideoLibrary")
    }

Import .so files

  1. Copy the jniLibs folder from the decompressed SDK package to the main folder of the app module. Then, declare the path of jniLibs in the build.gradle file of the app module.

    The following sample code provides an example:

    android {
     sourceSets.main {
         jni.srcDirs = []
         jniLibs.srcDir "src/main/jniLibs" 
     }
    }
  2. Load the dynamic-link libraries that are required for the SDK.

    These dynamic-link libraries have been loaded in the latest version of the SDK. You do not need to load the dynamic-link libraries.

    The following content describes the library files:

    libalivcffmpeg.so-------------Required third-party library for the SDK.
    libaliresample.so-------------------The library that is required for audio resampling. This library is optional.
  3. Add the dependencies that are required to upload short videos.

    The upload SDK and Object Storage Service (OSS) are required to upload short videos. If your application does not require this feature, skip this step.

    implementation 'com.aliyun.video.android:upload:1.6.4'
    implementation 'com.google.code.gson:gson:2.8.0'
    implementation 'com.squareup.okhttp3:okhttp:3.2.0'
    implementation 'com.aliyun.dpa:oss-android-sdk:+'
  4. Initialize the configurations.

    Call the onCreate method of the Application class in the app module. The following code provides an example:

    com.aliyun.vod.common.httpfinal.QupaiHttpFinal.getInstance().initOkHttpFinal();

Add permissions

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Note

Permissions need to be requested at runtime in Android 6.0 or later.

Configure the license file

After you obtain the license, perform the following steps to configure the license file. For more information about how to obtain a license, see Obtain and use a license of the short video SDK.

Add com.aliyun.alivc_license.licensekey and com.aliyun.alivc_license.licensefile to the AndroidManifest.xml file. The value of com.aliyun.alivc_license.licensekey is the value of LicenseKey, and the value of com.aliyun.alivc_license.licensefile is the path in which the license file is stored. The following sample code provides an example.

<application
   android:icon="@drawable/icon"
   android:label="@string/app_name" >
    <meta-data
         android:name="com.aliyun.alivc_license.licensekey"
         android:value="yourLicenseKey"/> // Enter the value of LicenseKey.
    <meta-data
       android:name="com.aliyun.alivc_license.licensefile"
       android:value="yourLicenseFile"/> // Enter the path in which the license file is stored. Example: assets/alivc_license/AliVideoCert.crt.
  ...
</application>

Configure obfuscation rules

You can configure the obfuscation rules in the proguard-rules.pro file. The following sample code provides an example:

######################Obfuscation configuration of the short video SDK#########################
-keep class com.aliyun.**{*;}
-keep class com.duanqu.**{*;}
-keep class com.qu.**{*;}
-keep class com.alibaba.**{*;}
-keep class component.alivc.**{*;}
-keep class com.alivc.**{*;}
-keep class org.webrtc.**{*;}
-keep class org.ugsv.**{*;}

References

For more information about API operations, see API references.

For more information about what to do next, see Initialize the short video SDK for Android.