Mini Program Playback Plugin
Polyv Cloud Video-on-Demand Mini Program Playback Plugin is built on Polyv's powerful backend capabilities and video processing technology, deeply integrated with its own video cloud services. It provides users with simple, fast, secure, and stable video playback services, allowing users to easily focus on their business development and enjoy an ultra-fast, high-definition playback experience.
Simply upload the video to the Polyv Cloud Video-on-Demand platform to obtain a vid, then use the plugin to play the video, enabling quick integration with your own business.
Click here to view this document on the official WeChat page.
WeChat Mini Program Integration Method
Apply to Use the Plugin
First, refer to WeChat's official Plugin Usage Documentation to apply for plugin permissions. When applying to use the plugin, fill in the following appid: wx4a350a258a6f7876.
After adding it, contact your account manager or the official "Polyv" customer service to request approval.
Import Plugin
For details, see the official documentation. Use the latest version of the plugin whenever possible.
// 使用插件前,使用者要在 app.json 中声明需要使用的插件
"plugins": {
"polyv-player": {
"version": "1.9.0",
"provider": "wx4a350a258a6f7876"
}
}
// 使用插件提供的自定义组件。在 json 文件定义需要引入的自定义组件时,使用 plugin:// 协议指明插件的引用名和自定义组件名
"usingComponents": {
"polyv-player": "plugin://polyv-player/player"
}
Using the Player Component
wxml file
<polyv-player
id="{{playerContext}}" // 组件ID
playerId="{{playerId}}" //播放器ID
vid="{{vid}}" // 视频ID
viewerInfo="{{viewerInfo}}" // 观众信息
autoplay="{{true}}" // 是否自动播放
bind:statechange="onStateChange" //事件绑定
>
<!-- 使用具名插槽,实现在全屏和非全屏的情况,在 video 组件上显示内容 -->
<view slot="custom">自定义插槽</view>
</polyv-player>
Attributes Supported by Component Elements
| Attribute | Type | Required | Default | Description | Minimum Version |
|---|---|---|---|---|---|
| id | String | Y | / | Component ID, must be globally unique. Used to obtain the player instance for manual playback control. | 0.1.0 |
| playerId | String | Y | / | Player ID, reserved attribute. Note: Must not be the same as id |
0.1.0 |
| vid | String | Y | / | Unique ID generated after uploading a video to the Polyv cloud on-demand platform. | 0.1.0 |
| width | String | N | 100% | Player width, supports rpx values and percentages, e.g., 300px or 100%. | 0.1.0 |
| height | String | N | / | Player height, supports rpx values and percentages. When empty, the parent container's height is used. | 0.1.0 |
| viewerInfo | Object | N | / | Custom viewer information. When set, the viewer information is included in the viewing behavior logs reported by the player. See: Viewer Information Settings and Statistics | 0.1.0 |
| sign | String | N | / | Signature required to play Web-encrypted videos, generated by the service provider's server and returned to the player. See: Playing Encrypted Videos | 0.1.0 |
| ts | Number | N | / | 13-digit millisecond timestamp required to play Web-encrypted videos. | 0.1.0 |
| appId | String | N | / | When playing Web-encrypted videos for a sub-account, the sub-account's appId must be provided. The sign calculation must use the corresponding secretkey. | 0.1.0 |
| autoplay | Boolean | N | false | Whether to autoplay. | 0.1.2 |
| muted | Boolean | N | false | Whether to play muted. | 0.1.2 |
| loop | Boolean | N | false | Whether to loop playback. | 0.1.2 |
| startTime | Number | N | / | Playback start time, indicating the second from which the video starts playing. The value must be less than the video duration. | 0.1.2 |
| poster | String, Boolean | N | Backend video cover image setting | Video cover image. Set to false to hide the cover image. | 1.9.0 |
| direction | Number | N | / | Sets the video orientation in fullscreen mode: 0 for normal portrait, 90 for 90-degree counterclockwise, -90 for 90-degree clockwise. If not specified, it is automatically determined based on the aspect ratio. | 0.1.2 |
| title | String | N | / | Title displayed at the top of the player in fullscreen mode. Not displayed when empty. | 0.1.2 |
| quality | Array | N | {1,2,3} | Video quality selection list: 1 for smooth, 2 for HD, 3 for Full HD. | 0.1.2 |
| defaultQuality | Number | N | / | Default video quality. Note: The player remembers the last used quality; if no record exists, the backend setting is used. |
0.1.2 |
| showQualityBtn | Boolean | N | true | Whether to display the quality selection button. | 0.1.2 |
| playbackRate | Array | N | [0.5,1.0,1.25,1.5,2.0] | Playback speed selection list, supports 0.5/0.8/1.0/1.25/1.5/2.0/3.0/4.0x speeds. Base library 2.6.3+ supports 2.0x speed, base library 3.7.5+ supports 3.0/4.0x speeds. See video for speed details. |
0.1.2 |
| showPlaybackRateBtn | Boolean | N | true | Whether to display the playback speed selection button. | 0.1.2 |
| showControls | Boolean | N | true | Whether to display playback controls. | 0.1.2 |
| showSettingBtn | Boolean | N | false | Whether to display the settings button in the control bar when not in fullscreen mode. | 0.1.2 |
| showProgressBar | Boolean | N | true | Whether to display the progress bar. | 0.1.2 |
| showFullscreenBtn | Boolean | N | true | Whether to display the fullscreen button. | 0.1.2 |
| useNativeControls | Boolean | N | false | Whether to use the native playback controls of the video component. When set to true, system-level picture-in-picture playback is enabled, allowing the video to continue playing in a small window on the device desktop. (Note: When set to true, features layered above the player like danmaku and marquee are unavailable.) | 1.11.0 |
| enableAutoRotation | Boolean | N | true | Whether to enable automatic fullscreen when the phone is in landscape mode. Takes effect when the system's auto-rotate setting is enabled. | 0.1.2 |
| isAllowSeek | String | N | yes | Whether to allow progress bar dragging: yes (allow), no (disallow), ifViewed (only allow dragging within the range of already played progress). | 0.1.2 |
| marqueeConfig | Object | N | / | Marquee parameter settings. See the marquee parameter description below. | 0.1.2 |
| logoConfig | Object | N | Backend player logo setting | Player logo settings: enable: whether to display the logo width/height: logo width and height, supports pixels and percentages, e.g., 100px or 10%. The logo maintains its original aspect ratio; if width and height don't match the original image ratio, the image is not stretched. The smaller side is used as the base, and the other side scales proportionally. When the player size changes (e.g., orientation switch), the logo scales proportionally. src: URL of the logo image position: logo position: 1 top-left, 2 top-right (default), 3 bottom-left, 4 bottom-right xOffset: horizontal offset, relative to the top-left corner of the player, supports percentages only yOffset: vertical offset, relative to the top-left corner of the player logoConfig:{enable:true,width:10%,src:'xxx.png',position:1,opacity:0.7,xOffset:10%,yOffset:2%} Note: Only the width parameter needs to be specified; height is displayed proportionally. |
0.1.2 |
| videoIntroConfig | Boolean | N | Backend player intro setting | Video intro settings: enable: whether to play the intro duration: display duration of the intro. If longer than the intro material duration, the material duration takes precedence. src: URL of the intro material, supports common video and image formats show-skip-btn: whether to display the skip intro button videoIntroConfig:{enable:true,duration:15,src:'xxx.mp4',show-skip-btn:false} |
0.1.4 |
| videoOutroConfig | Boolean | N | Backend player outro setting | Video outro settings, usage is the same as the intro parameters. | 0.1.4 |
| enablePlayGesture | Boolean | N | true | Whether to enable the double-tap gesture to toggle play/pause. | 0.4.0 |
| useBackgroundAudio | Boolean | N | false | Whether to enable background audio mode for audio playback in the background. | 0.4.0 |
| videoFit | String | N | contain | How the video is displayed when its size differs from the video container. Options: contain, fill, cover. | 0.10.0 |
| isControlBarFixed | Boolean | N | false | Whether to disable the auto-hide of the control bar. | 0.10.0 |
| pictureInPictureMode | string/Array | N | Sets the picture-in-picture mode: push, pop, empty string, or an array for multiple modes (e.g., ["push", "pop"]). | 0.13.0 | |
| showAudioBtn | Boolean | N | true | Whether to display the audio mode switch button. Note: The button is only shown if the vid has an associated audio file. | 0.13.0 |
| ban_history_time | Boolean | N | true | Whether to disable the resume playback feature. Disabled by default. Note: This configuration also affects remote resume playback (historyTimeType set to remote). Supported from version 0.14.0 onwards. | 0.14.0 |
| history_video_duration | Number | N | 5 | When resume playback is enabled, only videos longer than 5 minutes (default) support this feature. This parameter can be modified. Unit: minutes. Playback time points are not recorded during the first and last 10 seconds of the video. | 0.14.0 |
| historyTimeType | String | N | local | Value: "local" or "remote". The storage method for resume playback records. When set to local, it is stored in localStorage; when set to remote, it is stored on the Polyv server. Note: When configured as remote, subsequent records are not stored locally, and if both records exist, the remote value takes precedence. | 1.0.0 |
| vslideGesture | Boolean | N | false | Whether to enable brightness and volume adjustment gestures in non-fullscreen mode. | 1.1.0 |
| vslideGestureInFullscreen | Boolean | N | true | Whether to enable brightness and volume adjustment gestures in fullscreen mode. | 1.1.0 |
| pictureInPictureShowProgress | Boolean | N | false | Whether to display playback progress in picture-in-picture mode. | |
| showThumbnail | Boolean | N | true | Whether to display a preview thumbnail when dragging the progress bar. Note: Only takes effect in fullscreen mode. |
1.1.0 |
| showSrt | Boolean | N | true | Whether to enable subtitle display. | 1.12.0 |
| playsafe | String/Function | N | / | Authorization credential required to play encrypted videos. See: Playing Encrypted Videos for usage. Function usage example: playsafe: function(vid, next) { $.ajax({ url: 'token endpoint', type: "POST", data: obj, }).done(function(res) { next(res.data.token); }); }, |
1.15.0 |
| playsafeUrl | String | N | / | URL of the endpoint to obtain the credential for playing encrypted videos. Use either this or the playsafe parameter. | 1.15.0 |
Events Supported by Components
| Attribute | Description |
|---|---|
| bindstatechange | Playback state change event, includes loading (resource loading), playing (playing, including ads and video), ended (both ads and video finished), error. The callback function accepts two parameters: newstate and oldstate. |
| bindplaying | Triggered when playback starts or resumes. |
| bindpause | Triggered when playback is paused. |
| bindended | Triggered when playback reaches the end. |
| bindtimeupdate | Triggered when playback progress changes. event.detail = {currentTime, duration}. Trigger frequency: 250ms. |
| bindfullscreenchange | Triggered when the video enters or exits fullscreen. event.detail = {fullScreen, direction}. Valid direction values: vertical or horizontal. |
| bindwaiting | Triggered when the video is buffering. |
| binderror | Triggered when a video playback error occurs. |
| bindprogress | Triggered when loading progress changes. Only supports single segment loading. event.detail = {buffered}, percentage. |
| bindloadedmetadata | Triggered when video metadata is loaded. event.detail = {width, height, duration}. |
| bindcontrolstoggle | Triggered when controls are shown or hidden. event.detail = {show}. |
| bindenterpictureinpicture | Triggered when the player enters picture-in-picture mode. |
| bindleavepictureinpicture | Triggered when the player exits picture-in-picture mode. |
| bindseekCompleted | Triggered when a seek operation completes. |
| bindplaybackRateChange | Triggered when playback speed is changed. event.detail = {previousRate, currentRate}. previousRate: previous speed value, currentRate: current speed value. |
| bindprogressDragStart | Triggered when the progress bar thumb starts being dragged. event.detail = { duration, percent, predictionTime }. duration: total video duration, percent: thumb position percentage on the progress bar, range [0-100], predictionTime: current progress time (format: HH:mm:ss). |
| bindprogressDragMove | Triggered while the progress bar thumb is being dragged. event.detail = { duration, percent, predictionTime }. duration: total video duration, percent: thumb position percentage on the progress bar, range [0-100], predictionTime: current progress time (format: HH:mm:ss). |
| bindprogressDragEnd | Triggered when the progress bar thumb stops being dragged. event.detail = { duration, percent, predictionTime }. duration: total video duration, percent: thumb position percentage on the progress bar, range [0-100], predictionTime: current progress time (format: HH:mm:ss). |
| bindtoggleClickPlay | Triggered when the user actively plays/pauses via the UI. Return value: Boolean, indicating whether it is paused. |
Plugin API
You can obtain the player instance through a plugin, which includes the following methods:
| Name | Parameters | Return Value | Description
Example Code:
// 通过插件的自定义组件ID获取上下文,在一些特殊场景下,如触发小程序生命周期onShow或onHide,建议重新使用this.selectComponent('#myComponentID')再次获取一次组件上下文
var polyvPlayerContext = this.selectComponent('#myComponentID');
polyvPlayerContext.play(); // 播放
polyvPlayerContext.pause(); // 暂停
polyvPlayerContext.stop() //停止
polyvPlayerContext.seek(100); //跳转到指定位置,单位:秒
polyvPlayerContext.playbackRate(1.5); // 设置播放速率
var PolyvBarrageContext = this.selectComponent('#myComponentID').getPolyvBarrage(); // 获取弹幕实例
PolyvBarrageContext.sendDanmu({
color: '#ffffff',
text: this.data.danmuText
}); // 添加单条弹幕数据
PolyvBarrageContext.addDanmuData([{
color: '#ffffff',
text: this.data.danmuText
}]); // 添加多条弹幕数据
PolyvBarrageContext.closeDanmu(); // 关闭弹幕
PolyvBarrageContext.openDanmu(); // 开启弹幕
wx.onWindowResize(windowResize); // 监听窗口尺寸变化
var windowResize = function() {
var polyvSkinContext = this.selectComponent('#polyvPlayer').getPolyvSkin(); // 获取皮肤实例
polyvSkinContext.resize(); // 自适应进度条尺寸
}
Marquee Parameters
The marqueeConfig parameter properties are as follows:
| Attribute | Type | Required | Default | Description |
|---|---|---|---|---|
| text | String | Y | / | Marquee text content |
| fontSize | Integer | N | 16 | Marquee font size |
| fontColor | String | N | 0x000000 | Marquee font color |
| textAlpha | Float | N | 1 | Text transparency, 0~1 |
| border | Boolean | N | false | Whether to enable border |
| borderColor | String | N | 0x000000 | Border color |
| borderAlpha | Float | N | 1 | Border transparency, 0~1 |
| borderWidth | Integer | N | 5 | Border width, 0~255 |
| animationEffect | String | N | roll | Marquee animation effect: roll: scroll from right to left blink: blink at random positions |
| displayDuration | Number | N | 5 | Duration of a single marquee display, in seconds. When animation effect is roll, indicates the duration of a single scroll (from start of entry to complete exit) When animation effect is blink, indicates the duration from start of display to complete disappearance |
Error Code
| Error Code | Description | |
|---|---|---|
| #001 | Package expired. Please contact customer service to renew. | |
| #002 | Package data has been used up. Please contact customer service to purchase data. | |
| #003 | Video configuration file failed to load. This is usually due to network issues preventing the video configuration file from loading. It is recommended to check/switch the network and try again. | |
| #004 | Video does not exist. Please check if the vid is correct and whether the video has been deleted. | |
| #005 | Video review failed. Only videos with a "Published" status can be played. | |
| #007 | Video file failed to load. This is usually due to network issues preventing the video file from loading. It is recommended to check/switch the network and try again. | |
| #008 | Video file loading timed out. This is usually due to network issues causing the video file loading to time out. It is recommended to check/switch the network and try again. | |
| #009 | Video is under review. Only videos with a "Published" status can be played. | |
| #010 | Video is being encoded. Only videos with a "Published" status can be played. | |
| #012 | Marquee loading error. Please check if the parameters returned by the marquee interface are correct. For details, see: Authorized Playback and Marquee. | |
| #013 | Video authorized playback authentication failed. Please check the authorization authentication interface. For details, see: Authorized Playback and Marquee. | |
| #025 | For video copyright protection considerations, the player prohibits playing encrypted app videos on mini-programs. For details, see: Video Encryption. |
External Style Classes
Starting from version 0.15.0 of the plugin, external style classes are supported for customizing the skin style of the player's control bar. For detailed instructions and limitations regarding external style classes, please refer to the WeChat Mini Program official documentation. If style modifications are ineffective, it is recommended to add !important to increase priority.
Currently supported styles that can be modified:
| Custom Class | Description |
|---|---|
| ex-control-skin | Parent container of the control bar; modifying its style affects the entire player control bar. |
| ex-control-icon-play | Play icon in the control bar; can be modified via background-image. |
| ex-control-icon-pause | Pause icon in the control bar; can be modified via background-image. |
| ex-control-icon-setting | Settings icon in the control bar; can be modified via background-image. |
| ex-control-icon-audio | Audio mode icon in the control bar; can be modified via background-image. |
| ex-control-icon-back | Back icon in the control bar after entering fullscreen; can be modified via background-image. |
| ex-control-icon-fullscreen | Fullscreen icon in the control bar; can be modified via background-image. |
| ex-control-timeline | Container for time controls in the control bar; modifying its color affects the current playback time and video duration colors. |
| ex-control-current | Current player time under the time control in the control bar. |
| ex-control-duration | Video duration under the time control in the control bar. |
| ex-control-setting-panel | Settings panel that appears when clicking the "Settings" button; modifying its style affects the overall panel appearance. |
| ex-control-progress-dot | Dot on the progress bar in the control bar. |
| ex-control-progress-bar | Progress bar in the control bar. |
| ex-control-progress-load | Progress bar (loaded portion) in the control bar. |
| ex-control-progress-current | Progress bar (current playback progress) in the control bar. |
| ex-control-setting-btn | Option button on the right side of each function in the settings panel. |
| ex-control-setting-btn-select | Option button on the right side of each function in the settings panel (selected state). |
| ex-control-setting-text | Descriptive text on the left side of each function in the settings panel (e.g., speed). Also affects descriptive text on the bottom right of the control bar in fullscreen mode (e.g., speed 1x). |
Example wxml and wxss:
<polyv-vod-player
ex-control-icon-play="plv-custom-control-play" //自定义的class名
ex-control-icon-pause="plv-custom-control-pause"
ex-control-timeline="ex-control-timeline"
ex-control-current="ex-control-current"
ex-control-duration="ex-control-duration"
ex-control-icon-setting="ex-control-setting"
ex-control-setting-panel="ex-control-setting-panel"
ex-control-icon-fullscreen="ex-control-icon-fullscreen"
ex-control-icon-audio="ex-control-icon-audio"
ex-control-icon-back="ex-control-icon-back"
ex-control-progress-dot="ex-control-progress-dot"
ex-control-progress-bar="ex-control-progress-bar"
ex-control-progress-load="ex-control-progress-load"
ex-control-progress-current="ex-control-progress-current"
ex-control-skin="ex-control-skin"
ex-control-setting-btn="ex-control-setting-btn"
ex-control-setting-btn-select="ex-control-setting-btn-select"
ex-control-setting-text="ex-control-setting-text"
/>
.plv-custom-control-play {
background: url('https://{自定义的icon地址}/play.png') !important;
}
.plv-custom-control-pause {
background: url('https://{自定义的icon地址}/pause.png') !important;
}
.ex-control-timeline {
color: red;
}
Q&A
Q1. Does using the on-demand mini-program plugin require applying for a video-related qualification?
A1. When using the on-demand mini-program plugin, the mini-program typically does not need to reapply for the "Entertainment - Other Video" category qualification that the plugin itself possesses. However, it only supports non-personal mini-programs allowed by WeChat. The integrator must still ensure that the subject type, actual business content, and selected service category comply with WeChat's requirements, and adhere to the relevant regulations for using "video plugins" in mini-programs. If the mini-program does not use this plugin but instead uses self-developed components or other methods to provide video playback, it should apply for the corresponding service category based on the actual business. The final decision is subject to WeChat's review results. For details, refer to the mini-program plugin feature introduction and WeChat's open service categories.
Q2. The video authorized by the mini program cannot play?
A2. Currently, the mini-program on-demand plugin does not support videos authorized through the mini-program method. It is recommended to use WEB authorization.
