注冊(cè)

微信小程序媒體組件video視頻,微信小程序視頻組件庫(kù)

2017-12-22
導(dǎo)讀:video 視頻。 屬性名 類(lèi)型 默認(rèn)值 說(shuō)明 最低版本 src String 要播放視頻的資源地址 duration Number 指定視頻時(shí)長(zhǎng) 1.1.0 controls Boolean true 是否顯示默認(rèn)播放控件(播放/暫停按鈕、播放進(jìn)度、時(shí)間...

video


視頻。

 

屬性名 類(lèi)型 默認(rèn)值 說(shuō)明 最低版本
src String   要播放視頻的資源地址  
duration Number   指定視頻時(shí)長(zhǎng) 1.1.0
controls Boolean true 是否顯示默認(rèn)播放控件(播放/暫停按鈕、播放進(jìn)度、時(shí)間)  
danmu-list Object Array   彈幕列表  
danmu-btn Boolean false 是否顯示彈幕按鈕,只在初始化時(shí)有效,不能動(dòng)態(tài)變更  
enable-danmu Boolean false 是否展示彈幕,只在初始化時(shí)有效,不能動(dòng)態(tài)變更  
autoplay Boolean false 是否自動(dòng)播放  
loop Boolean false 是否循環(huán)播放 1.4.0
muted Boolean false 是否靜音播放 1.4.0
bindplay EventHandle   當(dāng)開(kāi)始/繼續(xù)播放時(shí)觸發(fā)play事件  
bindpause EventHandle   當(dāng)暫停播放時(shí)觸發(fā) pause 事件  
bindended EventHandle   當(dāng)播放到末尾時(shí)觸發(fā) ended 事件  
bindtimeupdate EventHandle   播放進(jìn)度變化時(shí)觸發(fā),event.detail = {currentTime: '當(dāng)前播放時(shí)間'} 。觸發(fā)頻率應(yīng)該在 250ms 一次  
bindfullscreenchange EventHandle   當(dāng)視頻進(jìn)入和退出全屏是觸發(fā),event.detail = {fullScreen: '當(dāng)前全屏狀態(tài)'} 1.4.0
objectFit String contain 當(dāng)視頻大小與 video 容器大小不一致時(shí),視頻的表現(xiàn)形式。contain:包含,fill:填充,cover:覆蓋  
poster String   默認(rèn)控件上的音頻封面的圖片資源地址,如果 controls 屬性值為 false 則設(shè)置 poster 無(wú)效  

 

video標(biāo)簽認(rèn)寬度300px、高度225px,設(shè)置寬高需要通過(guò)wxss設(shè)置width和height。

示例代碼:

<view class="section tc">
  <video src="{{src}}"   controls ></video>
  <view class="btn-area">
    <button bindtap="bindButtonTap">獲取視頻</button>
  </view>
</view>

<view class="section tc">
  <video id="myVideo" src="http://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">發(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: '',
    data: {
        src: '',
    danmuList: [
      {
        text: '第 1s 出現(xiàn)的彈幕',
        color: '#ff0000',
        time: 1
      },
      {
        text: '第 3s 出現(xiàn)的彈幕',
        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()
    })
  }
})

微信小程序媒體組件video視頻,微信小程序視頻組件庫(kù)

相關(guān)api:wx.createVideoContext

Bug & Tip

  1. tip:video組件是由客戶(hù)端創(chuàng)建的原生組件,它的層級(jí)是最高的。
  2. tip: 請(qǐng)勿在scroll-view中使用video組件。
  3. tip:css動(dòng)畫(huà)對(duì)video組件無(wú)效。
更多微信小程序開(kāi)發(fā)教程,可以關(guān)注hi小程序。
重磅推薦:小程序開(kāi)店目錄

第一部分:小商店是什么

第二部分:如何開(kāi)通一個(gè)小商店

第三部分:如何登錄小商店

第四部分:開(kāi)店任務(wù)常見(jiàn)問(wèn)題

第五部分:小商店可以賣(mài)什么

第六部分:HiShop小程序特色功能

第七部分:小程序直播

第八部分:小程序收貨/物流

第九部分:小程序怎么結(jié)算

第十部分:小程序客服

第十一部分:電商創(chuàng)業(yè)

第十二部分:小程序游戲開(kāi)發(fā)