「小程式JAVA實戰」小程式視訊元件與api介紹(50)
這次說下,小程式的視訊元件,之前在說小程式基礎的時候視訊元件沒說,現在說下。從屬性和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元件,具體使用方法點選這裡: ofollow,noindex" target="_blank">https://mp.weixin.qq.com/debug/wxadoc/dev/component/cover-view.html 。
百度未收錄
>>原創文章,歡迎轉載。轉載請註明:轉載自IT人故事會,謝謝!
>>原文連結地址: