微信小程序視頻組件控制wx.createVideoContext(videoId)

2020-07-23 10:47 更新

wx.createVideoContext(videoId)

創(chuàng)建并返回 video 上下文videoContext對(duì)象

videoContext

videoContext通過(guò) videoId 跟一個(gè) video 組件綁定,通過(guò)它可以操作一個(gè) video 組件。

videoContext對(duì)象的方法列表:

方法參數(shù)說(shuō)明最低版本
play無(wú)播放 
pause無(wú)暫停 
seekposition跳轉(zhuǎn)到指定位置,單位 s 
sendDanmudanmu發(fā)送彈幕,danmu 包含兩個(gè)屬性 text, color。 
playbackRaterate設(shè)置倍速播放,支持的倍率有 0.5/0.8/1.0/1.25/1.51.4.0
requestFullScreen無(wú)進(jìn)入全屏1.4.0
exitFullScreen無(wú)退出全屏1.4.0

示例代碼:

<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">發(fā)送彈幕</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: '',
  bindInputBlur: function(e) {
    this.inputValue = e.detail.value
  },
  bindSendDanmu: function () {
    this.videoContext.sendDanmu({
      text: this.inputValue,
      color: getRandomColor()
    })
  }
})
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)