From 8e003d317da31c555c5c746f62bd74c8dd46638b Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期二, 27 五月 2025 13:57:20 +0800
Subject: [PATCH] 视频播放记录完善
---
pages/tabbar/index/home.vue | 34 +++++++++++++++++++++++++++++++---
1 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/pages/tabbar/index/home.vue b/pages/tabbar/index/home.vue
index c42d93d..8d25e61 100644
--- a/pages/tabbar/index/home.vue
+++ b/pages/tabbar/index/home.vue
@@ -101,6 +101,10 @@
export default {
data() {
return {
+ startHidenTime: 0, // 璁板綍鍒囨崲鑷冲叾瀹冮〉闈㈢殑鏃堕棿锛岀敤浜庤绠楄棰戣鐪嬫椂闂村噺鍘荤殑閮ㄥ垎
+ totalHidenTime: 0, // 鎬诲叡闅愯棌椤甸潰鐨勬椂闂�
+ startPauseTime: 0, // 寮�濮嬫殏鍋滅殑鏃堕棿
+ totalPauseTime: 0, // 鎬诲叡鏆傚仠鐨勬椂闂�
playRecord: {
videoId: null,
viewDuration: 0, // 杩欎釜瑙嗛鎬诲叡瑙傜湅浜嗗涔�
@@ -121,7 +125,14 @@
}
},
onShow() {
- // this.loadVideos();
+ // 濡傛灉瑙嗛鎸変笅鏆傚仠鍚庡垏鎹㈤〉闈㈠啀鍥炲埌椤甸潰鏃讹紝鍙畻鏆傚仠鏃堕棿锛堝洜涓烘殏鍋滄椂闂村拰绂诲紑椤甸潰鏃堕棿鏄噸澶嶇殑锛屽彧绠椾竴涓級
+ if(this.startHidenTime !== 0 && this.currentVideoIsPlaying) {
+ const duration = Date.now() - this.startHidenTime
+ this.totalHidenTime += duration
+ }
+ },
+ onHide() {
+ this.startHidenTime = Date.now()
},
onLoad() {
this.loadVideos();
@@ -162,6 +173,13 @@
// 婊戝姩鍒囨崲瑙嗛
onSwiperChange(e) {
+ // 濡傛灉瑙嗛澶勪簬鏆傚仠鐘舵�佸線涓嬪埛瑙嗛锛岄偅涔堥渶瑕佸啀璁$畻涓�娆℃殏鍋滄椂闂�
+ if(!this.currentVideoIsPlaying) {
+ if(this.startPauseTime !== 0) {
+ const duration = Date.now() - this.startPauseTime
+ this.totalPauseTime += duration
+ }
+ }
// 淇濆瓨涓婁竴涓棰戠殑鎾斁璁板綍
this.savePlayRecord()
const oldIndex = this.currentIndex;
@@ -172,7 +190,8 @@
if (this.videoContexts[oldIndex]) {
this.videoContexts[oldIndex].pause();
}
-
+ this.currentVideoIsPlaying = true;
+ this.startPauseTime = 0;
// 鎾斁褰撳墠瑙嗛
if (this.videoContexts[this.currentIndex]) {
this.videoContexts[this.currentIndex].play();
@@ -217,11 +236,16 @@
if(this.playRecord.startPlayTime === 0) {
this.playRecord.startPlayTime = Date.now();
}
+ if(this.startPauseTime !== 0) {
+ const duration = Date.now() - this.startPauseTime
+ this.totalPauseTime += duration
+ }
},
// 瑙嗛鏆傚仠浜嬩欢
onPause(index) {
this.currentVideoIsPlaying = false;
+ this.startPauseTime = Date.now()
},
// 瑙嗛缁撴潫浜嬩欢
@@ -236,9 +260,11 @@
// 淇濆瓨鎾斁璁板綍
async savePlayRecord() {
+ console.log(Date.now(), this.playRecord.startPlayTime, this.totalHidenTime);
+
const data = {
videoId: this.playRecord.videoId,
- viewDuration: Date.now() - this.playRecord.startPlayTime,
+ viewDuration: Date.now() - this.playRecord.startPlayTime - this.totalHidenTime - this.totalPauseTime,
playAt: this.playRecord.playAt
}
this.playRecord = {
@@ -247,6 +273,8 @@
playAt: 0 ,// 杩欎釜瑙嗛鎾斁鍒板摢浜�
startPlayTime: 0 // 杩欎釜瑙嗛浠庝粈涔堟椂鍊欏紑濮嬫挱鏀剧殑
}
+ this.totalHidenTime = 0
+ this.totalPauseTime = 0
savePlayRecord(data)
}
}
--
Gitblit v1.8.0