Mini Program Playback Plugin
Polyv Cloud VOD Mini Program Player 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, and then use the plugin to play the video, enabling quick integration with your own business.
Click here to visit the official WeChat page to view this document.
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, please 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, uses the parent container's height. | 0.1.0 |
| viewerInfo | Object | N | / | Custom viewer information. When set, the viewer information is attached to the viewing behavior logs reported by the player. See: Viewer Information Setting and Statistics | 0.1.0 |
| sign | String | N | / | Signature required for playing Web encrypted videos, generated by the business server and returned to the player. See: Playing Encrypted Videos | 0.1.0 |
| ts | Number | N | / | 13-digit millisecond timestamp required for playing Web encrypted videos. | 0.1.0 |
| appId | String | N | / | When playing Web encrypted videos of a sub-account, the sub-account's appId must be provided. The sign calculation must use the corresponding secretkey of the account. | 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. Since v1.19.1, loop playback is disabled when the trial duration is less than the total video duration. | 0.1.2 |
| startTime | Number | N | / | Playback start time, indicating the second from which the video starts playing. The parameter value must be less than the video duration. Since v1.19.1, when effective trial is enabled, the start position does not exceed the trial boundary. | 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 counterclockwise 90 degrees, -90 for clockwise 90 degrees. If not specified, automatically determines based on aspect ratio. | 0.1.2 |
| title | String | N | / | Title displayed at the top of the video 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 UHD. | 0.1.2 |
| defaultQuality | Number | N | / | Default quality. Note: The player records the last used quality. If no record exists, it uses the value set in the backend. |
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.0 speeds. Base library 2.6.3+ supports 2.0x speed, base library 3.7.5+ supports 3.0/4.0x speed. See video for speed details. If the list contains the value 2, long-pressing the screen with a custom control bar enables temporary 2x speed playback. | 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 on the control bar in half-screen 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, enables system-level picture-in-picture playback, allowing the video to continue playing in a small window on the device desktop. (Note: When set to true, features like danmaku and marquee that overlay the player 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 and horizontal screen swipe to seek: yes allows, no disallows, ifViewed only allows dragging or swiping within the already played progress range. | 0.1.2 |
| marqueeConfig | Object | N | / | Marquee parameter settings. See the marquee parameter description below the document. | 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 pixel and percentage units, e.g., 100px or 10%. The logo maintains its original aspect ratio. If width and height do not match the original image ratio, the image is not stretched. The smaller side is used as the reference, and the other side is converted proportionally. When the player size changes (e.g., portrait/landscape 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, based on the top-left corner of the player, supports percentage only yOffset: vertical offset, based on 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 greater than the intro video 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 to play/pause gesture. | 0.4.0 |
| enableProgressGesture | Boolean | N | true | Whether to enable the horizontal screen swipe to seek gesture. Only effective when using a custom control bar. | 1.18.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 fits when its size differs from the video container size. 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 multiple modes via an array (e.g., ["push", "pop"]). Since v1.19.1, route picture-in-picture is disabled for HarmonyOS phones during effective trial; restored after trial ends. See Trial. | 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 (historyTimeType set to remote). Supported from version 0.14.0 onwards. Since v1.19.1, during effective trial, local resume progress is neither read nor written, and remote resume positioning is not executed. | 0.14.0 |
| history_video_duration | Number | N | 5 | When resume playback is enabled, only videos longer than 5 minutes support resume by default. This parameter can modify this duration, in minutes. Resume time points are not recorded during the first 10 seconds and last 10 seconds of playback. | 0.14.0 |
| historyTimeType | String | N | local | Value: "local" or "remote". The storage method for resume playback records. When set to local, stored in localStorage; when set to remote, stored on the Polyv server. Note: When configured as remote, subsequent records are not stored locally. 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 the preview thumbnail when dragging the progress bar. Note: Only effective 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 for playing encrypted videos. See: Playing Encrypted Videos for usage. Function usage: playsafe: function(vid, next) { $.ajax({ url: 'token API', type: "POST", data: obj, }).done(function(res) { next(res.data.token); }); }, |
1.15.0 |
| playsafeUrl | String | N | / | The API URL to obtain the credential for playing encrypted videos. Use this or the playsafe parameter. | 1.15.0 |
| trialEnabled | Boolean | No | false | Whether to enable trial playback; must be used with a valid trialDuration. | v1.19.1 |
| trialDuration | Number | No | 0 | Trial duration, in seconds. Must be a finite positive number; 0, negative, or invalid values disable trial restrictions. | v1.19.1 |
| trialMask | Object | No | {} | Configuration for the overlay displayed when the trial ends. Unspecified fields use default values. | v1.19.1 |
For trial viewing access examples, mask configuration, and platform restrictions, please refer to Trial Viewing.
Screen Gesture Description
When using a custom control bar (useNativeControls=false), the non-control area of the player supports the following gestures:
- During video playback, pressing and holding still on a non-control area of the player screen for approximately 500 ms temporarily switches playback to 2x speed; releasing or canceling the gesture restores the playback speed to what it was before the press.
- While temporary 2x speed is active, the player displays a "Playing at 2x speed" prompt. Temporary speed changes do not trigger the
playbackRateChangeevent. - When
playbackRatedoes not include the value2, long-pressing does not change the speed, and a prompt "Current video does not support speed playback" is shown.showPlaybackRateBtnonly controls whether the speed button is displayed and does not serve as a speed permission toggle. - Swiping left or right on a non-control area of the player screen allows previewing and jumping to a target playback time. During the swipe, only the target time is previewed; upon release, the player seeks to the target time in one go.
- Horizontal swiping on the screen follows the
enableProgressGestureandisAllowSeekconfigurations; whenisAllowSeek=ifViewedis active, it will not exceed the maximum watched progress. - Action buttons, the progress bar, and the settings panel retain their original interaction behaviors; double-tap to play, vertical volume/brightness adjustment, and system edge gestures remain as configured.
When using the WeChat native control bar (useNativeControls=true), pressing vslideGesture, vslideGestureInFullscreen, etc. retains the WeChat native gesture behavior according to the configuration, and does not display the above custom gesture prompts.
videoFit Usage Instructions
videoFit is used to set the scaling mode of the video frame within the player container.
| Value | Display Effect |
|---|---|
contain |
Maintains the original video aspect ratio and displays it completely; blank spaces may appear if the video and player proportions differ. |
fill |
Stretches the video to fill the player, which may cause distortion. |
cover |
Maintains the original video aspect ratio and fills the player; content exceeding the player boundaries will be cropped. |
<polyv-player
vid="{{vid}}"
videoFit="contain"
></polyv-player>
When a vertical 9:16 video needs to be fully displayed in a horizontal 16:9 player, it is recommended to set videoFit="contain". It is normal for blank spaces to appear on both sides of the player. If you need to fill the player completely, you can set cover, but the top and bottom parts of the video may be cropped.
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}. Fires every 250ms. |
| bindfullscreenchange | Triggered when video enters or exits fullscreen. event.detail = {fullScreen, direction}. Valid direction values are vertical or horizontal. |
| bindwaiting | Triggered when video buffering occurs. |
| 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 fully 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. |
| bindseekStarted | Triggered when the progress bar is dragged or a horizontal swipe initiates Seek. On horizontal swipe, event.detail = {message, vid, time}. |
| bindseekCompleted | Triggered when Seek completes or is denied by permissions. On successful horizontal swipe, event.detail = {message, vid, time}; on denial, includes reason; touchcancel does not submit Seek or trigger the completion event. |
| 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 dot or horizontal swipe starts dragging. event.detail = { duration, percent, predictionTime }, duration: total video duration, percent: target position percentage (range [0-100]), predictionTime: target time (format: HH:mm:ss). |
| bindprogressDragMove | Triggered during the dragging of the progress bar dot or horizontal swipe. event.detail = { duration, percent, predictionTime }, duration: total video duration, percent: target position percentage (range [0-100]), predictionTime: target time (format: HH:mm:ss). |
| bindprogressDragEnd | Triggered when the progress bar dot or horizontal swipe ends dragging. event.detail = { duration, percent, predictionTime }, duration: total video duration, percent: target position percentage (range [0-100]), predictionTime: target time (format: HH:mm:ss). |
| bindtoggleClickPlay | Triggered when the user actively plays/pauses via the UI. Returns a Boolean indicating whether it is paused. |
| bindtrialEnded | Triggered when a trial ends, once per trial session. event.detail = { vid, currentTime, trialDuration }, currentTime is the trial boundary. Minimum version: v1.19.1. |
| bindtrialAction | Triggered when the built-in trial overlay or button is clicked. event.detail = { vid, trialDuration }. The plugin does not handle navigation or payment. Minimum version: v1.19.1. |
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 animationEffect is roll, indicates the duration of a single scroll (from start of entry to complete exit) When animationEffect 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 more 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 networks and retry. | |
| #004 | Video does not exist. Please check if the vid is correct and if the video has been deleted. | |
| #005 | Video failed review. 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 networks and retry. | |
| #008 | Video file loading timed out. This is usually due to network issues causing the video file to load slowly. It is recommended to check/switch networks and retry. | |
| #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. See: Authorized Playback and Marquee. | |
| #013 | Video authorized playback authentication failed. Please check the authorization authentication interface. See: Authorized Playback and Marquee. | |
| #025 | For video copyright protection, the player prohibits playing encrypted app videos on mini-programs. 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 styles here 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. Changing the color here affects both current 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 styles here 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., "1x" for speed). |
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. Do I need to apply for a video-related qualification to use the on-demand mini-program plugin?
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, but 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. Unable to play videos authorized by the mini program?
A2. Currently, the mini-program on-demand plugin does not support videos using the mini-program authorization method. It is recommended to use WEB authorization.
