From 1a9a20cbcaba9333f6fd4933ce6c0cef063d4c06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BA=E7=8B=A8?= <18119604035@163.com> Date: Tue, 30 May 2023 16:40:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=86=E9=A2=91=E6=92=AD=E6=94=BE=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E9=85=8D=E7=BD=AE=E7=A6=81=E6=AD=A2=E6=8B=96=E5=8A=A8?= =?UTF-8?q?=E8=BF=9B=E5=BA=A6=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/course/video.tsx | 35 +++++++++++++++++++++++++-- src/pages/init/index.tsx | 5 ++++ src/store/system/systemConfigSlice.ts | 2 ++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/pages/course/video.tsx b/src/pages/course/video.tsx index af1c4c2..8208df0 100644 --- a/src/pages/course/video.tsx +++ b/src/pages/course/video.tsx @@ -22,7 +22,11 @@ const CoursePalyPage = () => { const [loading, setLoading] = useState(false); const [isLastpage, setIsLastpage] = useState(false); const [totalHours, setTotalHours] = useState([]); + const [playingTime, setPlayingTime] = useState(0); + const [watchedSeconds, setWatchedSeconds] = useState(0); const myRef = useRef(0); + const playRef = useRef(0); + const watchRef = useRef(0); useEffect(() => { getCourse(); @@ -45,6 +49,14 @@ const CoursePalyPage = () => { myRef.current = playDuration; }, [playDuration]); + useEffect(() => { + playRef.current = playingTime; + }, [playingTime]); + + useEffect(() => { + watchRef.current = watchedSeconds; + }, [watchedSeconds]); + const getCourse = () => { Course.detail(Number(params.courseId)).then((res: any) => { let totalHours: any = []; @@ -89,6 +101,7 @@ const CoursePalyPage = () => { }; setLastSeeValue(params); setLastSeeValue(params); + setWatchedSeconds(record.finished_duration); } getVideoUrl(params); setLoading(false); @@ -126,14 +139,32 @@ const CoursePalyPage = () => { color: systemConfig.playerBulletSecretColor || "red", opacity: Number(systemConfig.playerBulletSecretOpacity), }, - ban_drag: false, + ban_drag: systemConfig.playerIsDisabledDrag, last_see_pos: params, }); // 监听播放进度更新evt window.player.on("timeupdate", () => { - playTimeUpdate(parseInt(window.player.video.currentTime), false); + let currentTime = parseInt(window.player.video.currentTime); + if ( + systemConfig.playerIsDisabledDrag && + currentTime - playRef.current >= 2 && + currentTime > watchRef.current + ) { + window.player.seek(playRef.current); + } else { + setPlayingTime(currentTime); + playTimeUpdate(parseInt(window.player.video.currentTime), false); + } }); window.player.on("ended", () => { + if ( + systemConfig.playerIsDisabledDrag && + window.player.video.duration - playRef.current >= 2 + ) { + window.player.seek(playRef.current); + return; + } + setPlayingTime(0); setPlayendedStatus(true); playTimeUpdate(parseInt(window.player.video.currentTime), true); window.player && window.player.destroy(); diff --git a/src/pages/init/index.tsx b/src/pages/init/index.tsx index fd76a09..5b0aa75 100644 --- a/src/pages/init/index.tsx +++ b/src/pages/init/index.tsx @@ -41,6 +41,11 @@ export const InitPage = (props: Props) => { props.configData["player-is-enabled-bullet-secret"] === "1" ? true : false, + playerIsDisabledDrag: + props.configData["player-disabled-drag"] && + props.configData["player-disabled-drag"] === "1" + ? true + : false, playerBulletSecretText: props.configData["player-bullet-secret-text"], playerBulletSecretColor: props.configData["player-bullet-secret-color"], playerBulletSecretOpacity: diff --git a/src/store/system/systemConfigSlice.ts b/src/store/system/systemConfigSlice.ts index a166363..0fa2e39 100644 --- a/src/store/system/systemConfigSlice.ts +++ b/src/store/system/systemConfigSlice.ts @@ -9,6 +9,7 @@ type SystemConfigStoreInterface = { pcIndexFooterMsg: string; playerPoster: string; playerIsEnabledBulletSecret: boolean; + playerIsDisabledDrag: boolean; playerBulletSecretText: string; playerBulletSecretColor: string; playerBulletSecretOpacity: string; @@ -23,6 +24,7 @@ let defaultValue: SystemConfigStoreInterface = { pcIndexFooterMsg: "", playerPoster: "", playerIsEnabledBulletSecret: false, + playerIsDisabledDrag: false, playerBulletSecretText: "", playerBulletSecretColor: "", playerBulletSecretOpacity: "",