Commit 6bf7235a by kyle

播放轨迹

parent f5908be6
......@@ -23,15 +23,14 @@
<view class="courseBannerBox" v-if="!sliceshare">
<video v-if="isRenderVideo" id="myVideo" :src="courseInfo.filePathOss" :initial-time="viewTime"
object-fit="contain" class="videoBox" :poster="courseInfo.fileFirstImage"
:title="courseInfo.fileTitle" @loadedmetadata="loadedmetadata" @play="playVideo" @pause="pause"
@ended="ended" @timeupdate="timeupdate" style="width: 100vw;height: 320rpx;"></video>
:title="courseInfo.fileTitle" @play="playVideo" @pause="pause" @timeupdate="timeupdate" style="width: 100vw;height: 320rpx;"></video>
</view>
<!-- 课程详情图 -->
<view class="courseTitleContent">
<view class="courseTitle">
<view class="" style="width: 70%;">
<h4>{{courseInfo.fileTitle}}{{viewTime}}</h4>
<h4>{{courseInfo.fileTitle}}</h4>
</view>
<view class="shareF">
<view class="awakenApp" @click="jumpapp()" v-if="coursesharing == 1">
......@@ -140,7 +139,6 @@
},
data() {
return {
isPauseFlag:true,
isRenderVideo: false,
fileId: null,
lecturerId: null,
......@@ -172,6 +170,8 @@
shareCode: null,
sharelogin: false,
startTime: '',
newCourseInfo:{},
isPauseFlag:true
};
},
methods: {
......@@ -387,24 +387,22 @@
} else {
this.videoContext.pause();
if(this.fileId != item.fileId){
if(!this.isPauseFlag){
await this.saveVideoPlayback();
}
console.log('保存之后执行这里')
// 当点击的课程和当前播放的课程不一致时,执行此方法
uni.showLoading({
title: '加载中'
});
this.playbackId = null;
this.fileId = item.fileId;
this.courseInfo.packFileId = item.packFileId;
this.courseDetail()
this.newCourseInfo = {
fileId:item.fileId,
packFileId:item.packFileId,
}
if(this.isPauseFlag){
this.pause()
}
}
}
},
saveVideoPlayback() {
console.log('saveVideoPlayback')
return new Promise((resolve,reject)=>{
// 视频播放轨迹保存
const param = {
id: this.playbackId ? this.playbackId : null,
......@@ -416,12 +414,17 @@
viewTime: Math.floor(this.viewTime),
playbackStatus: this.viewTime >= this.totalTime ? '2' : '1'
}
return new Promise((resolve,reject)=>{
api.saveVideoPlayback(param).then(res => {
if (res['success']) {
this.playbackId = res['data']['id'];
console.log('执行了保存成功,入参=======',param)
resolve();
console.log('save已经执行完毕');
resolve('success');
}else{
reject('fail')
}
}).catch((err)=>{
reject('fail')
})
})
......@@ -439,26 +442,27 @@
if (res['success']) {
this.videoPlaybackInfo = res['data'];
console.log('查询视频播放轨迹结果=====',this.videoPlaybackInfo)
if(this.videoPlaybackInfo.viewTime < this.videoPlaybackInfo.totalTime){
this.viewTime = this.videoPlaybackInfo.viewTime;
this.totalTime = this.videoPlaybackInfo.totalTime;
}else{
this.totalTime = this.viewTime = 0;
}
this.viewTime = this.videoPlaybackInfo.viewTime
this.viewTime = this.videoPlaybackInfo.viewTime ? this.videoPlaybackInfo.viewTime : 0;
this.totalTime = this.videoPlaybackInfo.totalTime ? this.videoPlaybackInfo.totalTime : 0;
this.packFileId = this.videoPlaybackInfo.id ? this.videoPlaybackInfo.id : null;
this.isRenderVideo = true;
// 跳转到指定位置
this.videoContext.seek(this.viewTime);
uni.hideLoading();
}else{
this.isRenderVideo = true;
this.totalTime = this.viewTime = 0;
}
// 跳转到指定位置
this.videoContext.seek(this.viewTime);
this.videoContext.seek(thie.viewTime);
uni.hideLoading();
}
})
},
// 点击播放
playVideo(e) {
console.log('playVideo')
console.log('playVideo',this.totalTime,this.viewTime)
this.isPauseFlag = false;
console.log(this.viewTime,this.totalTime)
if(this.viewTime>=this.totalTime){
this.viewTime = 0;
this.videoContext.seek(this.viewTime);
......@@ -473,27 +477,21 @@
}, 20 * 1000)
}
},
pause(e) {
// // 暂停播放
async pause() {
console.log('pause')
this.isPauseFlag = true;
// 暂停播放
if (this.timer) {
clearInterval(this.timer)
}
if (this.viewTime >= this.totalTime) {
// 当播放完成的时候这里不触发
return;
} else {
this.saveVideoPlayback();
}
},
ended(e) {
console.log('ended')
// 播放到末尾
if (this.timer) {
clearInterval(this.timer)
const result = await this.saveVideoPlayback()
if(result=='success' && this.newCourseInfo.fileId){
console.log('新的课程要进行赋值查询了')
this.fileId = this.newCourseInfo.fileId;
this.courseInfo.packFileId = this.newCourseInfo.packFileId;
this.playbackId = null;
this.courseDetail();
}
this.saveVideoPlayback();
},
timeupdate(e) {
this.totalTime = e.detail.duration;
......@@ -576,11 +574,11 @@
this.switchTab(1);
this.loginType = uni.getStorageSync('loginType')
},
onReady() {
this.videoContext = uni.createVideoContext('myVideo');
},
onUnload() {
this.videoContext.pause();
this.saveVideoPlayback();
if (this.timer) {
clearInterval(this.timer)
......
......@@ -15,7 +15,7 @@
</view>
</view>
</view>
<view style="text-align: center;color: #cacaca;" v-if="!cffpFortuneDeductionList">暂无数据!</view>
<view class="noListTip" v-if="!cffpFortuneDeductionList || cffpFortuneDeductionList.length<=0">暂无数据!</view>
</view>
</template>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment