May 18, 2021 WeChat Mini Program Development Document
Base library 1.0.0 starts to support, and low versions need to be compatible.
Video (v2.4.0 supports same-layer rendering). Related api: wx.createVideoContext
Property | Type | The default | Required | Description | The lowest version |
---|---|---|---|---|---|
Src | string | Is | Resource address to play video, support network path, on-premises temporary path, cloud file ID (2.3.0) | 1.0.0 | |
duration | number | Whether | Specify the length of the video | 1.1.0 | |
controls | boolean | true | Whether | Whether to display the default playback control (play/pause button, playback progress, time) | 1.0.0 |
danmu-list | Array.<object> | Whether | Impeachment list | 1.0.0 | |
danmu-btn | boolean | false | Whether | Whether or not the bullet button is displayed is valid only at initialization and cannot be changed dynamically | 1.0.0 |
enable-danmu | boolean | false | Whether | Whether or not to display the impeachment screen is only valid at initialization and cannot be changed dynamically | 1.0.0 |
autoplay | boolean | false | Whether | Whether to play automatically | 1.0.0 |
loop | boolean | false | Whether | Whether to loop | 1.4.0 |
muted | boolean | false | Whether | Whether to mute playback | 1.4.0 |
initial-time | number | 0 | Whether | Specify where the video will initially play | 1.6.0 |
page-gesture | boolean | false | Whether | Whether to turn on the brightness and volume adjustment gestures in off-screen mode (discard, see vslide-gesture) | 1.6.0 |
direction | number | Whether | Set the orientation of the video at full screen, and if you don't specify it, you're automatically judging based on the aspect ratio | 1.7.0 | |
show-progress | boolean | true | Whether | If not set, the width is greater than 240 | 1.9.0 |
show-fullscreen-btn | boolean | true | no | Whether to display a full screen button | 1.9.0 |
show-play-btn | boolean | true | no | Whether the play button of the video bottom control bar is displayed | 1.9.0 |
show-center-play-btn | boolean | true | no | Whether to display the play button in the middle of the video | 1.9.0 |
enable-progress-gesture | boolean | true | no | Whether to turn on the hand gesture for control progress | 1.9.0 |
object-fit | string | contain | no | When the video size is inconsistent with the VIDEO container size, the video of the video | 1.0.0 |
poster | string | Whether | Video cover picture network resource address or cloud file ID (2.3.0). If the controls property value is false, setting the poster is not valid | 1.0.0 | |
show-mute-btn | boolean | false | Whether | Whether the mute button is displayed | 2.4.0 |
title | string | Whether | The title of the video, displayed at the top when full screen | 2.4.0 | |
play-btn-position | string | bottom | Whether | The position of the play button | 2.4.0 |
enable-play-gesture | boolean | false | Whether | Whether to turn on the play gesture, i.e. double-click to switch play/pause | 2.4.0 |
auto-pause-if-navigate | boolean | true | Whether | When you jump to another page of this small program, do you automatically pause video playback on this page? | 2.5.0 |
auto-pause-if-open-native | boolean | true | Whether | When you jump to another WeChat native page, do you automatically pause the video on this page? | 2.5.0 |
vslide-gesture | boolean | false | Whether | Do you turn on the brightness and volume adjustment gesture in non-full-screen mode (same page-gesture) | 2.6.2 |
vslide-gesture-in-fullscreen | boolean | true | Whether | In full-screen mode, turn on the Brightness and Volume Adjustment gesture | 2.6.2 |
ad-unit-id | string | Is | Video pre-ad unit ID, more details can refer to the open capacity video pre-ad | 2.8.1 | |
poster-for-crawler | string | Is | For scenes such as search as video cover shows, it is recommended to use a video cover image without play icon, which only supports network addresses | ||
show-casting-button | boolean | false | Whether | Displays the cast button. DLNA protocol is supported only by Android and under the same layer rendering | 2.10.2 |
picture-in-picture-mode | string/Array | Whether | Set small window mode: push, pop, empty string or set multiple modes in array form (e.g.: "push", "pop") | 2.11.0 | |
picture-in-picture-show-progress | boolean | false | Whether | Whether to display playback progress in small window mode | 2.11.0 |
enable-auto-rotation | boolean | false | Whether | Whether to turn on the phone cross-screen automatic full screen, when the system settings turn on automatic rotation | 2.11.0 |
show-screen-lock-button | boolean | false | Whether | Whether to display the lock screen button, only at full screen, the operation of the control bar after the lock screen | 2.11.0 |
bindplay | eventhandle | Whether | The play event is triggered when playback starts/continues | 1.0.0 | |
bindpause | eventhandle | Whether | The pause event is triggered when playback is paused | 1.0.0 | |
bindended | eventhandle | Whether | The end event is triggered when playing to the end | 1.0.0 | |
bindtimeupdate | eventhandle | Whether | Triggered when the playback progress changes, event.detail s.currentTime, duration. Trigger frequency 250ms once | 1.0.0 | |
bindfullscreenchange | eventhandle | Whether | Triggered when the video enters and exits full screen, event.detail is . . . fullScreen, direction, and the direction is valid for vertical or horizontal | 1.4.0 | |
bindwaiting | eventhandle | Whether | Triggered when the video is buffered | 1.7.0 | |
binderror | eventhandle | Whether | Triggered when an error occurs in video playback | 1.7.0 | |
bindprogress | eventhandle | Whether | Triggered when the load progress changes, only one load is supported. event.detail . . . | 2.4.0 | |
bindloadedmetadata | eventhandle | Whether | Triggered when the video metadata load is complete. event.detail = {width, height, duration} | 2.7.0 | |
bindcontrolstoggle | eventhandle | Whether | Switch controls to show triggers when hidden. event.detail = {show} | 2.9.5 | |
bindenterpictureinpicture | eventhandler | Whether | The player enters the window | 2.11.0 | |
bindleavepictureinpicture | eventhandler | Whether | The player exits the window | 2.11.0 | |
bindseekcomplete | eventhandler | Whether | Triggered when seek is complete | 2.12.0 |
The legal value of the direction
Value | Description | The lowest version |
---|---|---|
0 | Normal vertical | |
90 | The screen is 90 degrees counterclockwise | |
-90 | The screen is clockwise 90 degrees |
The legal value of object-fit
Value | Description | The lowest version |
---|---|---|
contain | Contains | |
fill | Fill | |
cover | Covered |
The legal value of play-btn-position
Value | Description | The lowest version |
---|---|---|
bottom | on controls bar | |
center | The middle of the video |
The legal value of picture-in-picture-mode
Value | Description | The lowest version |
---|---|---|
[] | Cancel the small window | |
push | The window is triggered when the push is routed | |
pop | The window is triggered when the pop is routed |
Format | Ios | Android |
---|---|---|
mp4 | √ | √ |
mov | √ | Ⅹ |
m4v | √ | Ⅹ |
3gp | √ | √ |
Avi | √ | Ⅹ |
m3u8 | √ | √ |
webm | Ⅹ | √ |
Format | Ios | Android |
---|---|---|
H.264 | √ | √ |
HEVC | √ | √ |
MPEG-4 | √ | √ |
VP9 | Ⅹ | √ |
The video window supports three trigger modes (setting the picture-in-picture-mode property on the component):
In addition, the windows support the following features:
When the player enters window mode, the page on which the player is located is in a hide state (triggering the onHide life cycle) and the page is not destroyed. When the window is closed, the page on which the player is located is unload (triggering the onUnload lifecycle).
Video label recognized width 300px, height 225px, set width height needs to be set via wxsswidth and height.
Example code:
<view class="section tc">
<video src="{{src}}" controls ></video>
<view class="btn-area">
<button bindtap="bindButtonTap">获取视频</button>
</view>
</view>
<view class="section tc">
<video id="myVideo" src="http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400" rel="external nofollow" danmu-list="{{danmuList}}" enable-danmu danmu-btn controls></video>
<view class="btn-area">
<button bindtap="bindButtonTap">获取视频</button>
<input bindblur="bindInputBlur"/>
<button bindtap="bindSendDanmu">发送弹幕</button>
</view>
</view>
function getRandomColor () {
let rgb = []
for (let i = 0 ; i < 3; ++i){
let color = Math.floor(Math.random() * 256).toString(16)
color = color.length == 1 ? '0' + color : color
rgb.push(color)
}
return '#' + rgb.join('')
}
Page({
onReady: function (res) {
this.videoContext = wx.createVideoContext('myVideo')
},
inputValue: '',
data: {
src: '',
danmuList: [
{
text: '第 1s 出现的弹幕',
color: '#ff0000',
time: 1
},
{
text: '第 3s 出现的弹幕',
color: '#ff00ff',
time: 3
}]
},
bindInputBlur: function(e) {
this.inputValue = e.detail.value
},
bindButtonTap: function() {
var that = this
wx.chooseVideo({
sourceType: ['album', 'camera'],
maxDuration: 60,
camera: ['front','back'],
success: function(res) {
that.setData({
src: res.tempFilePath
})
}
})
},
bindSendDanmu: function () {
this.videoContext.sendDanmu({
text: this.inputValue,
color: getRandomColor()
})
}
})
Related API: wx.createVideoContext