Skip to main content

Video

Video support Same-layer rendering. Related api:bn.createVideoContext

Example

Page({
data: {
id: 'myVideo',
},
onLoad(query) {
console.log('onload', this, query)
},
onShow() {
console.log(`[LifeCycle][Textarea] useEffect`)
setTimeout(() => {
if (!this.videoContext) throw new Error('Missing VideoContext')
this.videoContext.play()
}, 500)
},
onReady() {
this.videoContext = bn.createVideoContext('myVideo')
},

onPlay(e) {
console.log('[video] onPlay', e)
},
onPause(e) {
console.log('[video] onPause', e)
},
onEnded(e) {
console.log('[video] onEnded', e)
},
onTimeupdate(e) {
console.log('[video] onTimeupdate', e)
},
onFullscreenchange(e) {
console.log('[video] onFullscreenchange', e)
},
onLoadedmetadata(e) {
console.log('[video] onLoadedmetadata', e)
},
onError(e) {
console.log('[video] onError', e)
},
})

Bug & Tip

  • tip:video Default width 300px, altitude 225px, available via bxss Set the width and height.

Props

NameTypeDescriptionDefault
idstring
src requiredstringResource address to play video, support network path, local temporary path
durationnumber
controlsbooleanWhether to display the default playback controls/Pause on, playback progress, time)true
autoplaybooleanWhether to autoplayfalse
loopbooleanWhether to play on a loopfalse
mutedbooleanMute Playfalse
danmu-listarrayUnsupported properties, comment out default values to avoid Dart initialization errors.
danmu-btnboolean
enable-danmuboolean
init-timenumber
page-gestureboolean
directionDirectionType
show-progressbooleantrue
show-fullscreen-btnbooleantrue
show-play-btnbooleantrue
show-center-play-btnbooleantrue
enable-progress-gesturebooleantrue
object-fitstringWhen the video size is the same as the video When the container size is inconsistent, the presentation of the video"contain"
posterstring
show-mute-btnboolean
titlestring
play-btn-positionstring
enable-play-gestureboolean
auto-pause-if-navigatebooleanWhen jumping to other pages of this applet, whether to automatically suspend video playback on this page
auto-pause-if-open-nativebooleanWhen jumping to other WeChat native pages, whether to automatically suspend the video on this page
vslide-gesturebooleanUnder non-full-screen mode, whether to turn on the brightness and volume adjustment gesture
vslide-gesture-in-fullscreenbooleanIn full -screen mode, whether to turn on the brightness and volume adjustment gesture
show-bottom-progressbooleanWhether to show the bottom progress bartrue
show-casting-buttonbooleanDisplay screen button. Android takes effect under the same layer to support the DLNA protocol; iOS supports AirPlay and DLNA protocols. It can be operated through the correlation method of VideoContext.false
picture-in-picture-modearraySet the small window mode: Push, POP, empty string, or set multiple modes in the form of an array (such as: [push "," pop "])[]
picture-in-picture-init-positionstringThe initial display position of the small window in the small window mode is the format (alignment, y), where Alignment indicates that the left side of the small window adsorption screen is still the right side or right side. percentage
enable-auto-rotationbooleanWhether to open the full screen when the mobile phone is turned on, and take effect when the system is set to turn on the automatic rotation
show-screen-lock-buttonbooleanWhether the lock screen button is displayed, only displayed in full screen, the operation of the control bar after the lock screen
show-snapshot-buttonbooleanWhether to display a screenshot button, only display when it is full screen
show-background-playback-buttonbooleanWhether to show the background audio play button
background-posterstringThe notification bar icon after entering the background audio playback (Android is unique) 

Events

NameDescription
bindplayWhen it starts/Triggers play event while continuing playback
bindpauseTriggered when playback is paused pause event
bindendedTriggered when playback is paused pause event
bindtimeupdateTriggered when playback progress changes, event. detail = {currentTime, duration} Trigger frequency. 250ms first
bindfullscreenchangeTriggered when video enters and exits full-screen, event.detail = {fullScreen, direction},direction Valid values are vertical or horizontal
binderrorTriggered when video playback goes wrong
bindwaiting
bindprogress
bindloadedmetadata
bindcontrolstoggle
bindenterpictureinpicture
bindleavepictureinpicture
bindseekcomplete
bindcastinguserselect
bindcastingstatechange
bindcastinginterruptTriggered when the screen is interrupted