var app = getApp(); 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: { liveUrl: app.liveUrl, liveDetail: {}, videoContext: null, }, onShareAppMessage() { return { title: 'video', path: 'page/component/pages/video/video' } }, onReady() { // this.videoContext = wx.createVideoContext('myVideo') }, getLivePlan(livePlanId) { var self = this; app.restAjax.get(app.restAjax.path('{liveUrl}/app/liveplan/getliveplanbyidrelease/{livePlanId}', [self.data.liveUrl, livePlanId]), {}, null, function (code, data) { self.setData({ liveDetail: data }); self.videoContext = wx.createLivePlayerContext('liveVideo'); self.videoContext.play(); }, function (code, data) { app.dialog.msg(data.msg); }); }, goLiveRecord(event) { wx.navigateTo({ url: '../broadcastList/broadcastList?livePlanId=' + event.currentTarget.dataset.livePlanId, }) }, onLoad(option) { this.getLivePlan(option.livePlanId); this.saveBigdata(option.livePlanId) }, saveBigdata(id) { var params = "小程序" + id + "直播"; var info = { requestUrl: params } app.restAjax.get(app.restAjax.path(app.bigDataUrl + '/app/contentcensusrelease/log', []), info, null, function (code, data) { }, function (code, err) { }) }, 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) } })