您好,登錄后才能下訂單哦!
本篇文章為大家展示了怎么在微信小程序中實(shí)現(xiàn)一個(gè)視頻彈幕效果,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
wxml代碼
<!--pages/study/video/videoplay/videoplay.wxml--> <view class="page-body"> <view class="page-section tc"> <video id="myVideo" src="http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400" binderror="videoErrorCallback" danmu-list="{{danmuList}}" enable-danmu danmu-btn show-center-play-btn='{{false}}' show-play-btn="{{true}}" controls picture-in-picture-mode="{{['push', 'pop']}}" bindenterpictureinpicture='bindVideoEnterPictureInPicture' bindleavepictureinpicture='bindVideoLeavePictureInPicture' ></video> <view class="weui-label">彈幕內(nèi)容</view> <input bindblur="bindInputBlur" class="weui-input" type="text" placeholder="在此處輸入彈幕內(nèi)容" /> <button bindtap="bindSendDanmu" class="page-body-button" type="primary" formType="submit">發(fā)送彈幕</button> <navigator url="picture-in-picture" hover-class="other-navigator-hover"> <button type="primary" class="page-body-button" bindtap="bindPlayVideo">小窗模式</button> </navigator> </view> </view>
js代碼
// pages/study/video/videoplay/videoplay.js var that; function getRandomColor() { const 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({ onShareAppMessage() { return { title: 'video', path: 'page/component/pages/video/video' } }, onReady() { that = this; this.videoContext = wx.createVideoContext('myVideo') }, onHide() { }, inputValue: '', data: { src: '', danmuList: [{ text: '第 1s 出現(xiàn)的彈幕', color: '#ff0000', time: 1 }, { text: '第 3s 出現(xiàn)的彈幕', color: '#ff00ff', time: 3 }], }, bindInputBlur(e) { this.inputValue = e.detail.value }, bindButtonTap() { const that = this wx.chooseVideo({ sourceType: ['album', 'camera'], maxDuration: 60, camera: ['front', 'back'], success(res) { that.setData({ src: res.tempFilePath }) } }) }, bindVideoEnterPictureInPicture() { console.log('進(jìn)入小窗模式') }, bindVideoLeavePictureInPicture() { console.log('退出小窗模式') }, bindPlayVideo() { this.videoContext.play() }, bindSendDanmu() { // 利用循環(huán)和隨機(jī)數(shù)調(diào)整位置 var ranNum = Math.floor(Math.random()*10); var danmuList = []; for (let index = 0; index < 10; index++) { danmuList.push(''); } danmuList[ranNum] = this.inputValue; for (let index = 0; index < danmuList.length; index++) { this.videoContext.sendDanmu({ text: danmuList[index], color: '#ff0000' }); } }, videoErrorCallback(e) { console.log('視頻錯(cuò)誤信息:') console.log(e.detail.errMsg) } })
上述內(nèi)容就是怎么在微信小程序中實(shí)現(xiàn)一個(gè)視頻彈幕效果,你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。