const app = require('../../utils/util.js'); const tools = require('../../utils/tools.js'); var app1 = getApp(); Page({ data: { url: '', //播放地址 title: '', //视频标题 message: '', //视频信息 playTimes: 0, //播放次数 playVideoDuration: 0, // 从这个时间点开始播放 id: 0, //带过来的id studyLog: {}, //我得到的学习日志 intervalTime: 0, //隔五分钟清空重新计时 弹出信息确认在不在 video_real_time: 0, //实时播放进度 intervalCtx: null, videoContext: null, classInfo: {}, showWW: false, showChange: false, showfullChange:false, networkType: '', isAgree: false, //表示不同意用4G fullScreen:false }, isClass(sessionKey) { wx.request({ url: app.globalData.publicUrl + '/wx/student/selMyClas', method: "post", data: { sessionKey }, success: (res) => { if (res.data.code == 0) { this.setData({ classInfo: res.data.data }) } else { if (res.data.msg == "运行时异常:学员不可同时存在两个班级中。") { wx.showModal({ content: "学员不可同时存在多个班级中哦", showCancel: false, success(res) { if (res.confirm) { wx.switchTab({ url: '../index/index' }) } } }) return false; } else { wx.showModal({ content: "您当前还没有正在开放的班级!", showCancel: false, success(res) { if (res.confirm) { wx.switchTab({ url: '../index/index' }) } } }) return false; } } } }) }, // 视频出错了 videoErrorCallback: function (e) { console.log('视频错误信息:', e.detail.errMsg) }, // 计时 五分钟弹出一个弹框 calculateTime() { console.log(this.data.intervalTime) let _this = this; this.setData({ intervalTime: _this.data.intervalTime + 5 }) if (_this.data.intervalTime > 300) { _this.data.videoContext.pause() this.setData({ intervalTime: 0, showWW: true }) } }, // 点击开始播放视频 async bindplay() { // this.setData({ // clickTime: this.data.clickTime + 1 // }) this.setData({ intervalCtx: setInterval(() => { this.calculateTime() }, 5000) }) const netStatus = await this.getNetStatus(); this.setData({ networkType: netStatus }) if (netStatus != 'wifi' && !this.data.isAgree) { this.data.videoContext.pause() if(this.data.fullScreen){ this.setData({ showfullChange: true }) }else{ this.setData({ showChange: true }) } } wx.onNetworkStatusChange((res) => { if (this.data.networkType == "wifi" && res.networkType != "wifi" && !this.data.isAgree) { this.data.videoContext.pause() if(this.data.fullScreen){ this.setData({ showfullChange: true }) }else{ this.setData({ showChange: true }) } } }) }, goclose() { this.setData({ showChange: false, showfullChange:false, isAgree: false }) }, goon() { this.setData({ showChange: false, showfullChange:false, isAgree: true }) this.data.videoContext.play() }, fullScreenChange(e) { console.log(e.detail.fullScreen,"我是切换全屏的状态") this.setData({ fullScreen: e.detail.fullScreen }) }, startbf() { this.setData({ showWW: false }) this.data.videoContext.play() }, // 视频暂停 bindpause() { clearInterval(this.data.intervalCtx) }, // 得到录播列表 getdbArr(sessionKey) { let _this = this; wx.request({ method: "post", url: app.globalData.publicUrl + '/wx/course/selectRecordByCourseId', data: { sessionKey: sessionKey, courseId: _this.data.id }, success: (e) => { console.log(e, "888888888888888888") this.setData({ url: e.data.url, show: false, title: e.data.course.courseName, message: e.data.course.courseInfo, playTimes: e.data.course.playTimes }) } }) }, // 获取学习进度 getStudyLog(sessionKey) { let _this = this; wx.request({ method: "post", url: app.globalData.publicUrl + '/wx/course/getStudyLog', data: { sessionKey: sessionKey, courseId: _this.data.id }, success: (e) => { if (e.data.studyLog.isDone == 1) { _this.setData({ studyLog: e.data.studyLog }) } else { _this.setData({ studyLog: e.data.studyLog, playVideoDuration: e.data.studyLog.studyTime }) } } }) }, // 设置不可快进 timeUpdate: function (e) { //实时播放进度 秒数 let _this = this; let currentTime = parseInt(e.detail.currentTime) //当前播放秒数 let studyTime = 'studyLog.studyTime' this.setData({ [studyTime]: currentTime }) if (this.data.classInfo.id != -1) { let aa = 1; let jump_time; if (_this.data.video_real_time == 0) { jump_time = parseInt(_this.data.playVideoDuration) + parseInt(_this.data.video_real_time) } else { jump_time = parseInt(_this.data.video_real_time) } if (aa == 1) { if (currentTime > jump_time && currentTime - jump_time > 3) { _this.data.videoContext.seek(_this.data.video_real_time) wx.showToast({ title: '未完整看完该视频,不能快进', icon: 'none', duration: 2000, }) } } } _this.setData({ video_real_time: currentTime, //实时播放进度 }) }, // 修改学习进度 chechEndStatus: function () { if (this.data.classInfo.id != -1) { let _this = this; // let currentTime = parseInt(e.detail.currentTime) let isDone = 'studyLog.isDone' this.setData({ [isDone]: 1 }) wx.request({ method: "post", url: app.globalData.publicUrl + '/wx/course/updateStudyLog', data: { studyLog: _this.data.studyLog }, success: (e) => { wx.showModal({ showCancel: false, content: "该录播视频已经看完啦,快去完成其他任务吧!", success(res) { if (res.confirm) { wx.navigateBack({ delta: 1 }) } } }) } }) } }, onUnload() { let _this = this; clearInterval(_this.data.intervalCtx) if (_this.data.classInfo.id != -1) { let stydyrecord = _this.data.playVideoDuration; if (stydyrecord == null) { stydyrecord == 0 } if (_this.data.studyLog.studyTime > stydyrecord) { wx.request({ method: "post", url: app.globalData.publicUrl + '/wx/course/updateStudyLog', data: { studyLog: _this.data.studyLog }, success: (e) => { console.log(e, "我修改进度成功了") } }) } } }, onHide() { let _this = this; clearInterval(_this.data.intervalCtx) if (_this.data.classInfo.id != -1) { let stydyrecord = _this.data.playVideoDuration; if (stydyrecord == null) { stydyrecord == 0 } if (_this.data.studyLog.studyTime > stydyrecord) { wx.request({ method: "post", url: app.globalData.publicUrl + '/wx/course/updateStudyLog', data: { studyLog: _this.data.studyLog }, success: (e) => { console.log(e, "我修改进度成功了") } }) } } }, async getNetStatus() { return new Promise((resolve, reject) => { wx.getNetworkType({ success: (res) => { console.log(res.networkType, "999999") resolve(res.networkType); } }) }); }, async onLoad(options) { this.setData({ id: options.id, videoContext: wx.createVideoContext('myVideo') }) const sessionKey = await tools.checkSessionAndLogin(); this.isClass(sessionKey); this.getStudyLog(sessionKey); this.getdbArr(sessionKey); }, })