Polyv Help Center

Help Center

2 Quick Integration

Updated: 2025-10-27 14:51:14

Before integration, you need to register on the Polyv official website and activate the cloud video-on-demand service.

1. Gradle Configuration

  1. Add maven仓库 to the build.gradle file of Project:
allprojects {
    repositories {
        google()
        //阿里云的镜像库
        maven {url "http://maven.aliyun.com/nexus/content/groups/public/"}
        maven {url 'http://maven.aliyun.com/nexus/content/repositories/releases/'}
        mavenCentral()
        //阿里云效关于central的镜像
        maven{
            url 'https://maven.aliyun.com/repository/public'
        }
        //阿里云效仓库,必须添加
        maven {
            credentials {
                username '609cc5623a10edbf36da9615'
                password 'EbkbzTNHRJ=P'
            }
            url 'https://packages.aliyun.com/maven/repository/2102846-release-8EVsoM/'
        }
    }
}
  1. Add the ndk declaration to the build.gradle file of app:
android {
    ...
    defaultConfig {
        ...
        ndk {
            abiFilters 'arm64-v8a', 'armeabi-v7a', 'armeabi', 'x86_64', 'x86'
        }
    }
    ...
}

The abiFilters can be filtered based on actual conditions. It is recommended to configure it as arm64-v8a、armeabi-v7a、x86. Do not use only armeabi, as using only armeabi may cause issues such as audio-video desynchronization and frame skipping on some devices.

  1. Add dependencies to the build.gradle file of app:
implementation 'com.android.support:support-annotations:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:multidex:1.0.3'

implementation 'net.polyv.android:polyvPlayer:<sdk版本>'//SDK核心包
implementation 'net.polyv.android:polyvDownload:<sdk版本>'//SDK下载功能
implementation 'net.polyv.android:polyvUpload:<sdk版本>'//SDK上传功能
implementation 'net.polyv.android:polyvSub:<sdk版本>'//弹幕、截图功能中使用

implementation 'de.hdodenhof:circleimageview:2.2.0'//圆形imageview,音频封面图使用
implementation 'com.github.bumptech.glide:glide:4.7.1'//demo中的ppt图片加载使用
implementation "com.daimajia.swipelayout:library:1.2.0@aar"//demo中下载列表使用

// 投屏sdk
implementation "net.polyv.android:media-cast-adapter-rx:1.0.5"

The SDK core package is mandatory for video playback. Other dependencies can be imported as needed. If importing too many libraries causes the 64k method limit to be exceeded, refer to the Demo solution.

2. Configure AndroidManifest.xml

  1. Add the corresponding permissions to the AndroidManifest.xml file of the application:
<!-- 基础权限 -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_LOGS" />
<!-- WRITE_EXTERNAL_STORAGE属于android6.0运行时权限-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Android 10 起需要精确定位才能获取wifi详细信息  -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

Note 1: For versions prior to 2.18.0, if adapting to Android 11 (i.e., targetSdkVersion >= 30), the pointer tagging feature must be disabled (Android official documentation on pointer tagging). Refer to the following code to modify AndroidManifest.xml to disable pointer tagging.

  <application 
    android:allowNativeHeapPointerTagging="false">
    ...
  </application>

3. Initialize the SDK

3.1 Obtain the SDK Encryption String

The SDK encryption string is visible on the official website under Cloud Video-on-Demand - Settings - API Interface. For more details, see Initialization - Setting SDK.

Note: The SDK加密串 provided by the Polyv backend is only a fixed encryption method for demonstration purposes. For setting the SDK encryption string, developers should use their own encryption method. See the official usage solution for details.

3.2 Initialize the SDK

Note: For versions 2.16.5.1 and later, httpdns must be started at an appropriate time after obtaining user privacy authorization. For example, in the demo, call PolyvSDKClient.getInstance().enableHttpDns() in PolyvMainActivity to start httpdns.

PolyvSDKClient.getInstance().enableHttpDns(true);

Initialize the SDK in the onCreate() method of the Application when the application starts.

//获取 PolyvSDKClient实例
PolyvSDKClient client = PolyvSDKClient.getInstance();
//设置SDK加密串
client.settingsWithConfigString("你的SDK加密串", "加密密钥", "加密向量");
//初始化SDK设置
client.initSetting(getApplicationContext());
//设置学员唯一标识
client.setViewerId("学员唯一标识");
//设置下载保存目录
PolyvSDKClient.getInstance().setDownloadDir("下载视频保存的目录");

4. Video Playback

Video operations depend on the VID, which is the unique identifier for a video. The VID is automatically generated after the video is successfully uploaded to the backend.

PolyvVideoView is the main class of the video player. After declaring and initializing it in the layout file, use videoView.setVid(VID) to enable automatic video playback.

<com.easefun.polyvsdk.video.PolyvVideoView
    android:id="@+id/polyv_video_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
PolyvVideoView videoView = findViewById(R.id.polyv_video_view);
videoView.setVid(vid);

5. Video Download

Downloaded videos are uniformly saved to the directory set by PolyvSDKClient.getInstance().setDownloadDir(File). If not set, videos cannot be downloaded and saved. Video downloads are based on the VID and bitrate. PolyvDownloaderManager is a wrapper class for video download operations, providing basic download functionality.

// 设置下载队列总数,多少个视频能同时下载。(默认是1,设置负数和0是没有限制)
PolyvDownloaderManager.setDownloadQueueCount(1);
//获取downloader
PolyvDownloader downloader = PolyvDownloaderManager.getPolyvDownloader(vid, bitrate);
//开始下载
downloader.start(getApplicationContext);

The getPolyvDownloader() method saves the download task to a Map, ensuring the uniqueness of the download task. This method returns an instance of PolyvDownloader, which is the concrete implementation class for video downloads and can start and stop specific download tasks.

联系客服,在线咨询