Mini Program SDK
Note: The mini program SDK for on-demand video playback has relatively simple functionality, only providing basic features such as obtaining video playback addresses and sending logs. It is recommended to use the mini program plugin for on-demand video playback, which offers easier integration and richer features.
Mini Program On-Demand SDK Download (Click to download and consult)
Preparation Before Development
- In the WeChat Developer backend for the mini program, go to Settings - Development Settings - Server Domain Names and configure the [request合法域名]
- router.polyv.net
- hls.videocc.net
- prtas.videocc.net
- player.polyv.net

Start Development
1. Get Video Playback Address
index.js
import polyv from '../../utils/polyv.js';
Page({
...
onReady: function () {
//获取视频播放地址
let vid = "e8888b74d1bd0f19e821d6185279564a_e";
let vidObj = {
vid: vid,
callback: function(videoInfo){
that.setData({
// 按数组下标递增的顺序分别为流畅、高清、超清视频的分辨率
videoSrc: videoInfo.src[0]
});
}
};
polyv.getVideo(vidObj);
}
}
Option Description
vid
Type: String Description: Video ID
callback(videoInfo)
Type: Function Description: Triggered when video information is successfully retrieved Parameter: videoInfo Parameter Type: object Parameter Description:
| Parameter | Parameter Description |
|---|---|
| src | Array: Playback addresses for multiple bitrates. After successful retrieval, select one bitrate to set as the video component's src. The resolutions in the array, in ascending index order, are smooth, HD, and ultra-HD respectively |
| poster | Video cover image |
| title | Video title |
| teaser_url | Video teaser; determine image/video type by the returned link suffix |
| duration | Total video duration |
| timeoutflow | Returns only this attribute with value true, indicating the plan has expired |
| outflow | Returns only this attribute with value true, indicating insufficient plan traffic |
params
Type: object Description: Custom parameters for playback logs
| Optional Parameter Value | Description |
|---|---|
| param1 | User ID |
| param2 | Viewer nickname |
sid
Type: String Description: Custom ID in the POLYV backend viewing logs
ts
Type: String Description: Web authorization encrypted timestamp; add when using web-authorized video playback
sign
Type: String Description: Web authorization encrypted verification sign; add when using web-authorized video playback
appId
Type: String Description: Sub-account appId; add when using a sub-account for web-authorized video playback. Additionally, the sign calculation must use the corresponding account's secretkey
2. Get Video Preview Playback Address
onReady: function () {
//获取视频预览播放地址
let vid = "e8888b74d1bd0f19e821d6185279564a_e";
let vidObj = {
vid: vid,
callback: function(videoInfo){
that.setData({
videoSrc: videoInfo.src[0]
});
}
};
polyv.getPreviewVideo(vidObj);
}
3. Send Playback Logs
//需要绑定video组件bindtimeupdate时间并调用polyv.timeUpdate
<video id="polyvVideo" class="vp-v" src="{{videoSrc}}" bindtimeupdate="timeUpdate"></video>
timeUpdate: function (e) {
polyv.timeUpdate(e);
}
ps: Please note that parameter e is mandatory
4. Destroy Playback Log Timer
onUnload: function () {
polyv.destroy();
}
Update Notes
- Fixed compatibility issue with non-encrypted video playback failure under WeChat version 6.7.3 (2018-10-10).
