1. 程式人生 > >「小程序JAVA實戰」小程序視頻組件與api介紹(51)

「小程序JAVA實戰」小程序視頻組件與api介紹(51)

contex ret 原生 join -a cover 客戶 min ++

轉自:https://idig8.com/2018/09/22/xiaochengxujavashizhanxiaochengxushipinzujianyuapijieshao50/

這次說下,小程序的視頻組件,之前在說小程序基礎的時候視頻組件沒說,現在說下。從屬性和api都說下。https://github.com/limingios/wxProgram.git 中No.15

視頻組件

  • 官網介紹
    >https://developers.weixin.qq.com/miniprogram/dev/component/video.html

技術分享圖片

  • demo
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()
    })
  }
})



<view class="section tc"> <video id="myVideo" src="https://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400" 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>

PS: 最後補充一下video的註意事項:
1. video 組件是由客戶端創建的原生組件,它的層級是最高的。
2. 請勿在 scroll-view 中使用 video 組件。
3. css 動畫對 video 組件無效。

如果想在video組件上添加組件,可以使用cover-view組件,具體使用方法點擊這裏:https://mp.weixin.qq.com/debug/wxadoc/dev/component/cover-view.html。

「小程序JAVA實戰」小程序視頻組件與api介紹(51)