You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.4 KiB
68 lines
1.4 KiB
Page({
|
|
data: {
|
|
list: [{
|
|
id: '1001',
|
|
title: '中国古代数学科普',
|
|
videoUrl: '/static/img/123.mp4'
|
|
},
|
|
{
|
|
id: '1002',
|
|
title: '中国古代数学科普',
|
|
videoUrl: '/static/img/123.mp4'
|
|
},
|
|
{
|
|
id: '1003',
|
|
title: '当中国古代数学科普',
|
|
videoUrl: '/static/img/123.mp4'
|
|
},
|
|
{
|
|
id: '1004',
|
|
title: '当中国古代数学科普',
|
|
videoUrl: '/static/img/123.mp4'
|
|
}
|
|
]
|
|
},
|
|
|
|
// 创建视频上下文
|
|
videoCtx: wx.createVideoContext('myVideo'),
|
|
|
|
playVideo: function(e) {
|
|
// 停止之前正在播放的视频
|
|
this.videoCtx.stop();
|
|
// 更新视频地址
|
|
this.setData({
|
|
src: e.currentTarget.dataset.url
|
|
});
|
|
// 播放新的视频
|
|
this.videoCtx.play();
|
|
},
|
|
|
|
getDanmu: function(e) {
|
|
this.setData({
|
|
danmuTxt: e.detail.value
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 发送弹幕
|
|
*/
|
|
sendDanmu: function(e) {
|
|
let text = this.data.danmuTxt;
|
|
this.videoCtx.sendDanmu({
|
|
text: text,
|
|
color: this.getRandomColor() // 使用 this.getRandomColor() 调用函数
|
|
});
|
|
},
|
|
|
|
// 定义 getRandomColor 函数
|
|
getRandomColor: function() {
|
|
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('');
|
|
}
|
|
});
|