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 URLs 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 Inquire)
Preparation Before Development
- In the WeChat Developer backend for Mini Programs, go to Settings - Development Settings - Server Domain Configuration and set the [request合法域名]
- router.polyv.net
- hls.videocc.net
- prtas.videocc.net
- player.polyv.net

Start Development
1. Get Video Playback URL
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 obtained Parameter: videoInfo Parameter Type: object Parameter Description:
| Parameter | Parameter Description |
|---|---|
| src | Array: Playback URLs for multiple bitrates. After successful retrieval, select one bitrate to set as the video component's src. In ascending order of array index, they correspond to smooth, HD, and ultra-HD video resolutions respectively |
| poster | Video cover image |
| title | Video title |
| teaser_url | Video teaser; determine image/video type based on the returned link suffix |
| duration | Total video duration |
| timeoutflow | Returns only this attribute with a value of true, indicating the plan has expired |
| outflow | Returns only this attribute with a value of 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 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 requires the corresponding secretkey for the account
2. Get Video Preview Playback URL
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 and compatible the issue of non-encrypted video playback failure under the new WeChat version 6.7.3 (2018-10-10).
