# VideoContext

VideoContext Example, you can use the wx.createVideoContext Get.

VideoContext adopt id With one. video Component binding, the corresponding video Component.

# method

# VideoContext.play()

Play the video

# VideoContext.pause()

Pause video

# VideoContext.stop()

Stop the video

# VideoContext.seek(number position)

Jump to the specified location

# VideoContext.sendDanmu(Object data)

Send barrage

# VideoContext.playbackRate(number rate)

Set playback speed

# VideoContext.requestFullScreen(Object object)

Go to full screen. If you have custom content that needs to be displayed at full screen, place the content node in the video Node.

# VideoContext.exitFullScreen()

Exit Full Screen

# VideoContext.showStatusBar()

Display status bar, valid for iOS full screen only

# VideoContext.hideStatusBar()

Hide the status bar, only available in full iOS screen

# VideoContext.exitPictureInPicture()

Exit window, which can be called on any page

# VideoContext.requestBackgroundPlayback()

Enter background audio playback mode.

# VideoContext.exitBackgroundPlayback()

Exit background audio playback mode.

# sample code

Preview with Developer Tool

<view class="section tc">
  <video id="myVideo" src="http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownloadfilekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400" enable-danmu danmu-btn controls></video>
  <view class="btn-area">
    <input bindblur="bindInputBlur"/>
    <button bindtap="bindSendDanmu">Send barrage</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 (and) {
    this.inputValue = and.detail.value
  },
  bindSendDanmu () {
    this.videoContext.sendDanmu({
      text: this.inputValue,
      color: getRandomColor()
    })
  }
})