微信小程序視頻彈幕位置隨機
更新時間:2021年04月30日 07:47:22 投稿:lijiao
這篇文章主要介紹了微信小程序視頻彈幕位置隨機,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了微信小程序視頻彈幕位置隨機的具體代碼,供大家參考,具體內(nèi)容如下
最近更新開發(fā)工具之后,微信小程序視頻播放彈幕不再自動隨機,所以就用了一個比較取巧的方法(多條空彈幕和自己要發(fā)送的彈幕一起發(fā)送,利用隨機數(shù)控制順序就行了);
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 style="margin: 30rpx auto" class="weui-label">彈幕內(nèi)容</view>
<input bindblur="bindInputBlur" class="weui-input" type="text" placeholder="在此處輸入彈幕內(nèi)容" />
<button style="margin: 30rpx auto" bindtap="bindSendDanmu" class="page-body-button" type="primary" formType="submit">發(fā)送彈幕</button>
<navigator style="margin: 30rpx auto" 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('進入小窗模式')
},
bindVideoLeavePictureInPicture() {
console.log('退出小窗模式')
},
bindPlayVideo() {
this.videoContext.play()
},
bindSendDanmu() {
// 利用循環(huán)和隨機數(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('視頻錯誤信息:')
console.log(e.detail.errMsg)
}
})
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Javascript中類式繼承和原型式繼承的實現(xiàn)方法和區(qū)別之處
其它的面向?qū)ο蟪绦蛟O(shè)計語言都是通過關(guān)鍵字來解決繼承的問題。但是javascript中并沒有定義這種實現(xiàn)的機制。接下來通過本文給大家介紹Javascript中類式繼承和原型式繼承的實現(xiàn)方法和區(qū)別,需要的朋友可以參考下2017-04-04
javascript:google 向上向下滾動特效,兼容IE6,7,8,FF
這個代碼是我之前帶網(wǎng)上找的,因為今天再次用到,所以記錄下來,免得以后都找不到,我現(xiàn)在想去搜它的說明文檔都搜不到!2010-08-08
JavaScript實現(xiàn)url地址自動檢測并添加URL鏈接示例代碼
寫一個簡單的聊天系統(tǒng),發(fā)出Htpp的Url實現(xiàn)跳轉(zhuǎn)加上a標(biāo)簽,下面是具體的實現(xiàn),感興趣的朋友不要錯過2013-11-11

