Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat Small Program API Video VideoContext


May 18, 2021 WeChat Mini Program Development Document


Table of contents


VideoContext

VideoContext instance, available at wx.createVideoContext.

VideoContext binds to a video component via id, operating the corresponding video component.

Method:

VideoContext.exitFullScreen()

Base library 1.4.0 starts to be supported, and low versions need to be compatible.

Exit full screen

VideoContext.exitPictureInPicture(Object object)

Exit the window, which can be called on any page

Parameters

Object object

Property Type The default Required Description
success function Whether The interface calls a successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)

VideoContext.hideStatusBar()

Base library 2.1.0 starts to support, and low versions need to be compatible.

Hide the status bar, valid only at iOS full screen

VideoContext.pause()

Pause the video

VideoContext.play()

Play the video

VideoContext.playbackRate(number rate)

Base library 1.4.0 starts to be supported, and low versions need to be compatible.

Set up multiple playback

parameter

number rate

The magnification, support 0.5 / 0.8 / 1.0 / 1.25 / 1.5, 2.6.3 support 2.0 times the speed

VideoContext.requestFullScreen(Object object)

The base library 1.4.0 began support, the low version needs to be compatible.

Enter the full screen.If there is a custom content, you need to display the content node to the VIDEO node.

parameter

Object object

Attributes type Defaults Required illustrate Minimum version
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

The legal value of object.direction

Value Description The lowest version
0 Normal vertical
90 The screen is 90 degrees counterclockwise
-90 The screen is clockwise 90 degrees

VideoContext.seek(number position)

Jump to the specified location

Parameters

number position

Jump to the location, unit s

VideoContext.sendDanmu(Object data)

Send the impeachment screen

Parameters

Object data

Impeachment content

Property Type The default Required Description
text string Is Impeachment text
color string Whether Impeachment color

VideoContext.showStatusBar()

Base library 2.1.0 starts to support, and low versions need to be compatible.

Displays the status bar, valid only at iOS full screen

VideoContext.stop()

Base library 1.7.0 starts to support, and low versions need to be compatible.

Stop the video

The sample code

Preview the effect in the developer tool

<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"  enable-danmu danmu-btn controls></video>
  <view class="btn-area">
    <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 (res) {
    this.videoContext = wx.createVideoContext('myVideo')
  },
  inputValue: '',
  bindInputBlur (e) {
    this.inputValue = e.detail.value
  },
  bindSendDanmu () {
    this.videoContext.sendDanmu({
      text: this.inputValue,
      color: getRandomColor()
    })
  }
})