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, and 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, please contact your account manager or the official "Polyv" customer service to request approval.
Importing Plugins
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, viewer info is attached to the playback behavior logs reported by the player. See: Viewer Info Setting and Statistics | 0.1.0 |
| sign | String | N | / | Signature required for playing 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 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. | 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, automatically determined 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 super HD. | 0.1.2 |
| defaultQuality | Number | N | / | Default 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 show 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, base library 3.7.5+ supports 3.0/4.0x. See video for speed details. Including the value 2 enables temporary 2x speed playback by long-pressing the screen when using a custom control bar. | 0.1.2 |
| showPlaybackRateBtn | Boolean | N | true | Whether to show the playback speed selection button. | 0.1.2 |
| showControls | Boolean | N | true | Whether to show playback controls. | 0.1.2 |
| showSettingBtn | Boolean | N | false | Whether to show the settings button on the control bar in half-screen mode. | 0.1.2 |
| showProgressBar | Boolean | N | true | Whether to show the progress bar. | 0.1.2 |
| showFullscreenBtn | Boolean | N | true | Whether to show 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 rotated to landscape. 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 swipe seeking: yes to allow, no to disallow, ifViewed to allow only within the already played progress range. | 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 show 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 do not match the original image ratio, the image is not stretched. The smaller side is used as the reference, 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, based on the top-left corner of the player, supports percentages 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 is required; 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 show 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 |
| enableProgressGesture | Boolean | N | true | Whether to enable the horizontal swipe Seek gesture on the video. Only takes effect 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 within the video container when sizes differ. 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 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 show 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 modify the threshold, in minutes. Playback time points within the first 10 seconds and last 10 seconds of the video are not recorded for resume. | 0.14.0 |
| historyTimeType | String | N | local | Values: "local" or "remote". The storage method for resume playback records. When set to local, records are stored in localStorage. When set to remote, records are 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 show playback progress in picture-in-picture mode. | |
| showThumbnail | Boolean | N | true | Whether to show preview thumbnails 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 for playing encrypted videos. See: Playing Encrypted Videos for usage. Function usage: 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 | / | The API endpoint URL to obtain the credential for playing encrypted videos. Use this or the playsafe parameter. | 1.15.0 |
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 will not switch speeds, and a prompt "Current video does not support speed playback" will appear.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. - Operation 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), press vslideGesture, vslideGestureInFullscreen, etc. to retain the WeChat native gesture behavior, without displaying 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 video's original 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 video's original aspect ratio and fills the player; content outside the player's range 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 space 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 ad and video playback completed), 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: every 250ms. |
| bindfullscreenchange | Triggered when the video enters or exits fullscreen. event.detail = {fullScreen, direction}. Valid direction values are 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 fully loaded. event.detail = {width, height, duration}. |
| bindcontrolstoggle | Triggered when controls are toggled between show and hide. 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 on the screen initiates a Seek. On horizontal swipe, event.detail = {message, vid, time}. |
| bindseekCompleted | Triggered when a Seek is completed or denied by permissions. On successful horizontal swipe, event.detail = {message, vid, time}; on denial, includes reason; touchcancel does not submit a Seek and does not 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 dragging ends. 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. 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 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 try again. | |
| #004 | Video does not exist. Please check if the vid is correct and if 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 networks 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 networks 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. 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 considerations, 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 explanations 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 control bar appearance. |
| 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 (visible 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 playback 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. 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. However, it only supports non-personal mini-programs allowed by WeChat. The integrator must still ensure that the entity 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 employs 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. Can't 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.
