提交 fc5e752f authored 作者: 王鹏飞's avatar 王鹏飞

fix: 修复观看时长统计错误的问题

上级 ba1d71fa
...@@ -66,14 +66,13 @@ export default { ...@@ -66,14 +66,13 @@ export default {
throttleWait: 5, // 秒 throttleWait: 5, // 秒
progress: { progress: {
cpt: 0, // 当前播放时间 cpt: 0, // 当前播放时间
mpt: 0, // 视频时长 mpt: 0, // 当前播放最大时间
progress: 0, // 进度 progress: 0, // 进度
pt: 0 // 累计播放时间 pt: 0 // 累计观看时间
}, },
player: null, player: null,
watchedTimePoint: [], // 视频观看的时间点 watchedTime: 0,
timer: null, watchedTimePoint: [] // 视频观看的时间点
isPlaying: false
} }
}, },
watch: { watch: {
...@@ -148,12 +147,10 @@ export default { ...@@ -148,12 +147,10 @@ export default {
if (this.progress.cpt) { if (this.progress.cpt) {
this.player.seek(this.progress.cpt) this.player.seek(this.progress.cpt)
} }
// 更新视频观看总时长
this.updateWatchTime()
}, },
// 当前播放时间更新 // 当前播放时间更新
onTimeupdate(time) { onTimeupdate(time) {
this.isPlaying = true time = Math.floor(time)
const ppts = this.chatperResources.ppts || [] const ppts = this.chatperResources.ppts || []
let index = this.chatperResources.ppts.findIndex( let index = this.chatperResources.ppts.findIndex(
item => item.ppt_point > time item => item.ppt_point > time
...@@ -161,14 +158,16 @@ export default { ...@@ -161,14 +158,16 @@ export default {
index = index !== -1 ? index - 1 : ppts.length - 1 index = index !== -1 ? index - 1 : ppts.length - 1
this.$emit('change-ppt', index) this.$emit('change-ppt', index)
const durations = this.player.getDuration() const durations = this.player.getDuration()
// 更新视频时间 // 更新当前播放时间
this.progress.cpt = parseInt(time) this.progress.cpt = time
// 更新视频时长 // 观看的最大点
this.progress.mpt = parseInt(durations) this.progress.mpt = Math.max(time, this.progress.mpt)
const hasTimePoint = this.watchedTimePoint.includes(this.progress.cpt) const hasTimePoint = this.watchedTimePoint.includes(this.progress.cpt)
if (!hasTimePoint) { if (!hasTimePoint) {
this.watchedTimePoint.push(this.progress.cpt) this.watchedTimePoint.push(this.progress.cpt)
} }
// 更新视频观看总时长
this.updateWatchTime(time)
// 更新视频进度,10秒更新一次 // 更新视频进度,10秒更新一次
if (this.throttled) { if (this.throttled) {
this.throttled(time, durations) this.throttled(time, durations)
...@@ -228,7 +227,6 @@ export default { ...@@ -228,7 +227,6 @@ export default {
}, },
// 更新章节视频进度 // 更新章节视频进度
updateChapterVideoProgress(time, durations) { updateChapterVideoProgress(time, durations) {
// this.progress.pt += this.throttleWait
// 登录用户信息 // 登录用户信息
const user = window.G.UserInfo const user = window.G.UserInfo
const params = { const params = {
...@@ -249,24 +247,20 @@ export default { ...@@ -249,24 +247,20 @@ export default {
this.watchedTimePoint = [] this.watchedTimePoint = []
}, },
// 更新观看总时长 // 更新观看总时长
updateWatchTime() { updateWatchTime(time) {
this.timer && clearInterval(this.timer) if (time === this.watchedTime) {
return
}
this.watchedTime = time
// 增加跳过片头时间 // 增加跳过片头时间
if (this.isSkip && !this.progress.pt) { if (this.isSkip && !this.progress.pt) {
this.progress.pt = this.skipTime + this.throttleWait this.progress.pt = this.skipTime + 20
} }
// 默认增加时间 // 默认增加时间
this.progress.pt = this.progress.pt || this.throttleWait this.progress.pt = this.progress.pt || 20
this.timer = setInterval(() => { // 播放倍速
// safair 浏览器下有bug const speed = this.player._originalPlaybackRate || 1
// const status = this.player.getStatus() this.progress.pt += 1 * speed
if (this.isPlaying) {
// 播放倍速
const speed = this.player._originalPlaybackRate || 1
this.progress.pt = this.progress.pt + 1 * speed
}
this.isPlaying = false
}, 1000)
} }
}, },
beforeMount() { beforeMount() {
...@@ -274,9 +268,6 @@ export default { ...@@ -274,9 +268,6 @@ export default {
this.getChapterVideo() this.getChapterVideo()
// 获取视频进度 // 获取视频进度
this.getChapterVideoProgress() this.getChapterVideoProgress()
},
destroyed() {
this.timer && clearInterval(this.timer)
} }
} }
</script> </script>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论