Commit 6bf7235a by kyle

播放轨迹

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