12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- 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({
- onReady(res) {
- this.videoContext = wx.createVideoContext('myVideo')
- },
- inputValue: '',
- data: {
- src: '',
- danmuList: [
- {
- text: '第 1s 出现的弹幕',
- color: '#ff0000',
- time: 1
- },
- {
- text: '第 3s 出现的弹幕',
- 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
- })
- }
- })
- },
- bindSendDanmu() {
- this.videoContext.sendDanmu({
- text: this.inputValue,
- color: getRandomColor()
- })
- }
- })
|