提交 694f3ed0 编写于 作者: X xiaoyucoding

modify: 优化发送弹幕的逻辑

上级 35f28e27
...@@ -6,19 +6,18 @@ ...@@ -6,19 +6,18 @@
<video id="myVideo" src="https://www.dcloud.io/uniapp/wap2appvsnative.mp4" @error="videoErrorCallback" :danmu-list="danmuList" <video id="myVideo" src="https://www.dcloud.io/uniapp/wap2appvsnative.mp4" @error="videoErrorCallback" :danmu-list="danmuList"
enable-danmu danmu-btn controls></video> enable-danmu danmu-btn controls></video>
</view> </view>
<view class="uni-list uni-common-mt"> <view class="uni-list uni-common-mt">
<view class="uni-list-cell"> <view class="uni-list-cell">
<view> <view>
<view class="uni-label">弹幕内容</view> <view class="uni-label">弹幕内容</view>
</view> </view>
<view class="uni-list-cell-db"> <view class="uni-list-cell-db">
<input @blur="bindInputBlur" class="uni-input" type="text" placeholder="在此处输入弹幕内容" /> <input v-model="danmuValue" class="uni-input" type="text" placeholder="在此处输入弹幕内容" />
</view> </view>
</view> </view>
</view> </view>
<view class="uni-btn-v"> <view class="uni-btn-v">
<button @tap="bindSendDanmu" class="page-body-button">发送弹幕</button> <button @click="sendDanmu" class="page-body-button">发送弹幕</button>
</view> </view>
</view> </view>
</view> </view>
...@@ -30,7 +29,6 @@ ...@@ -30,7 +29,6 @@
return { return {
title: 'video', title: 'video',
src: '', src: '',
inputValue: '',
danmuList: [{ danmuList: [{
text: '第 1s 出现的弹幕', text: '第 1s 出现的弹幕',
color: '#ff0000', color: '#ff0000',
...@@ -41,30 +39,28 @@ ...@@ -41,30 +39,28 @@
color: '#ff00ff', color: '#ff00ff',
time: 3 time: 3
} }
] ],
danmuValue: ''
} }
}, },
onReady: function (res) { onReady: function(res) {
this.videoContext = uni.createVideoContext('myVideo') this.videoContext = uni.createVideoContext('myVideo')
}, },
methods: { methods: {
bindInputBlur: function (e) { sendDanmu: function() {
this.inputValue = e.target.value
},
bindSendDanmu: function () {
this.videoContext.sendDanmu({ this.videoContext.sendDanmu({
text: this.inputValue, text: this.danmuValue,
color: this.getRandomColor() color: this.getRandomColor()
}) });
this.danmuValue = '';
}, },
videoErrorCallback: function (e) { videoErrorCallback: function(e) {
console.log(e.target.errMsg);
uni.showModal({ uni.showModal({
content:e.target.errMsg, content: e.target.errMsg,
showCancel:false showCancel: false
}) })
}, },
getRandomColor: function () { getRandomColor: function() {
const rgb = [] const rgb = []
for (let i = 0; i < 3; ++i) { for (let i = 0; i < 3; ++i) {
let color = Math.floor(Math.random() * 256).toString(16) let color = Math.floor(Math.random() * 256).toString(16)
...@@ -78,5 +74,7 @@ ...@@ -78,5 +74,7 @@
</script> </script>
<style> <style>
video{width:690upx;} video {
width: 690upx;
}
</style> </style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册