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({ data: { src: '', }, onShareAppMessage() { return { title: 'video', path: 'page/component/pages/video/video' } }, onReady() { this.videoContext = wx.createVideoContext('myVideo') }, onHide() { }, inputValue: '', 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() { console.log('1') this.videoContext.play() }, bindSendDanmu() { this.videoContext.sendDanmu({ text: this.inputValue, color: getRandomColor() }) }, videoErrorCallback(e) { console.log('视频错误信息:') console.log(e.detail.errMsg) } })