From a6d09fa89f874f2707653099e565c591bce8f5b6 Mon Sep 17 00:00:00 2001 From: harry Date: Fri, 13 Mar 2020 13:42:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=B2=BE=E7=A1=AE=E6=9C=89=E6=95=88?= =?UTF-8?q?=E8=A7=82=E7=9C=8B=E8=A7=86=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../courses/Video/video-play/index.jsx | 58 +++++++++++++------ 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/public/react/src/modules/courses/Video/video-play/index.jsx b/public/react/src/modules/courses/Video/video-play/index.jsx index 8972c588d..84b465014 100644 --- a/public/react/src/modules/courses/Video/video-play/index.jsx +++ b/public/react/src/modules/courses/Video/video-play/index.jsx @@ -1,5 +1,26 @@ import React, { useRef, useEffect, useCallback } from 'react' +Object.defineProperty(HTMLMediaElement.prototype, 'playing', { + get: function () { + return !!(this.currentTime > 0 && !this.paused && !this.ended && this.readyState > 2) + } +}) + +function compareNumbers(a, b) { + return a - b; +} + +function getTotalEffectTime(pos) { + pos.sort(compareNumbers) + let sum = 0 + for (let i = 0; i < pos.length - 1; i++) { + let v = pos[i + 1] - pos[i] + if (v < 21) { + sum += v + } + } + return sum +} const regex = /(android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini)/i //接口文档 https://www.showdoc.cc/educoder?page_id=4029884447803706 export default ({ src, videoId, logWatchHistory, courseId = null }) => { @@ -12,22 +33,21 @@ export default ({ src, videoId, logWatchHistory, courseId = null }) => { const device = deviceMatch ? deviceMatch[0] : 'pc' let totalDuration = 0 - let totalTimePlayed = 0 let sumTimePlayed = 0 let lastUpdatedTime = 0 - let lastEffectUpdatedTime = 0 let logId = null let initLog = false let timeTick = 20 //记录频率 默认20s let logCount = 1 let isLoging = false let isSeeking = false + let pos = []//播放时间点集 const log = useCallback((callback) => { let params = {} if (logId) { params['log_id'] = logId - params['watch_duration'] = totalTimePlayed //当前观看视频时长,拖放进度条,重复的视频片段观看时,不会把重复的时长累积进来,最大时长是视频的总时长 + params['watch_duration'] = getTotalEffectTime(pos) //当前观看视频时长,拖放进度条,重复的视频片段观看时,不会把重复的时长累积进来,最大时长是视频的总时长 params['total_duration'] = sumTimePlayed //累计观看视频时长,拖放进度条,重复的视频片段观看时,重复观看时长要累积进来 } else { if (courseId) { @@ -82,6 +102,7 @@ export default ({ src, videoId, logWatchHistory, courseId = null }) => { useEffect(() => { function onPlay() { + pos.push(el.current.currentTime) if (!initLog) { initLog = true log() @@ -92,13 +113,12 @@ export default ({ src, videoId, logWatchHistory, courseId = null }) => { log(() => { logId = null logCount = 1 - totalTimePlayed = 0 lastUpdatedTime = 0 sumTimePlayed = 0 initLog = false isLoging = false - lastEffectUpdatedTime = 0 isSeeking = false + pos = [] }) } @@ -106,18 +126,16 @@ export default ({ src, videoId, logWatchHistory, courseId = null }) => { if (!isSeeking) { let newTime = el.current.currentTime let timeDiff = newTime - lastUpdatedTime - let effectTimeDiff = newTime - lastEffectUpdatedTime - if (effectTimeDiff > 0) { - totalTimePlayed += effectTimeDiff - lastEffectUpdatedTime = newTime - } - sumTimePlayed += Math.abs(timeDiff) - lastUpdatedTime = newTime - - if (!isLoging) { - if (sumTimePlayed - logCount * timeTick >= 0) { - logCount++ - log() + //currenttime update before Seeking & Seeked fired + if (Math.abs(timeDiff) < 0.5) { + sumTimePlayed += Math.abs(timeDiff) + lastUpdatedTime = newTime + if (!isLoging) { + if (sumTimePlayed - logCount * timeTick >= 0) { + logCount++ + pos.push(lastUpdatedTime) + log() + } } } } @@ -126,11 +144,13 @@ export default ({ src, videoId, logWatchHistory, courseId = null }) => { function onSeeking() { isSeeking = true - lastUpdatedTime = el.current.currentTime - lastEffectUpdatedTime = el.current.currentTime } function onSeeked() { + if (el.current.playing) { + pos.push(el.current.currentTime, lastUpdatedTime) + } + lastUpdatedTime = el.current.currentTime isSeeking = false } From 168bb77c886a806ff7a837883ad2add64b2ee31a Mon Sep 17 00:00:00 2001 From: caicai8 <1149225589@qq.com> Date: Fri, 13 Mar 2020 14:06:17 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=85=B3=E5=8D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tpm/shixunchild/shixunchildCss/Challenges.css | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/public/react/src/modules/tpm/shixunchild/shixunchildCss/Challenges.css b/public/react/src/modules/tpm/shixunchild/shixunchildCss/Challenges.css index 19451dff7..3350a5ad2 100644 --- a/public/react/src/modules/tpm/shixunchild/shixunchildCss/Challenges.css +++ b/public/react/src/modules/tpm/shixunchild/shixunchildCss/Challenges.css @@ -178,23 +178,23 @@ white-space: nowrap; } -.icon-bianji_Hover,.icon-xiayi_Hover,.icon-shangyi_Hover,.icon-shanchu_Hover{ - color:#BBBBBB !important; -} +/* .icon-bianji_Hover,.icon-xiayi_Hover,.icon-shangyi_Hover,.icon-shanchu_Hover{ + color: rgb(80, 145, 255) !important; +} */ -.icon-bianji_Hover:hover{ +.icon-bianji_Hover{ color: rgb(80, 145, 255) !important; } -.icon-xiayi_Hover:hover{ +.icon-xiayi_Hover{ color: rgb(51, 189, 140) !important; } -.icon-shangyi_Hover:hover{ +.icon-shangyi_Hover{ color: rgb(51, 189, 140) !important; } -.icon-shanchu_Hover:hover{ +.icon-shanchu_Hover{ color:rgb(255, 85, 85) !important; } .ysliconfont{