已看完视频显示进度条

This commit is contained in:
禺狨 2023-05-30 17:47:12 +08:00
parent c8e9f8cc7a
commit cec5251da4

View File

@ -27,6 +27,7 @@ const CoursePalyPage = () => {
const myRef = useRef(0); const myRef = useRef(0);
const playRef = useRef(0); const playRef = useRef(0);
const watchRef = useRef(0); const watchRef = useRef(0);
const totalRef = useRef(0);
useEffect(() => { useEffect(() => {
getCourse(); getCourse();
@ -57,6 +58,10 @@ const CoursePalyPage = () => {
watchRef.current = watchedSeconds; watchRef.current = watchedSeconds;
}, [watchedSeconds]); }, [watchedSeconds]);
useEffect(() => {
totalRef.current = hour.duration;
}, [hour]);
const getCourse = () => { const getCourse = () => {
Course.detail(Number(params.courseId)).then((res: any) => { Course.detail(Number(params.courseId)).then((res: any) => {
let totalHours: any = []; let totalHours: any = [];
@ -102,6 +107,8 @@ const CoursePalyPage = () => {
setLastSeeValue(params); setLastSeeValue(params);
setLastSeeValue(params); setLastSeeValue(params);
setWatchedSeconds(record.finished_duration); setWatchedSeconds(record.finished_duration);
} else {
setWatchedSeconds(res.data.hour.duration);
} }
getVideoUrl(params); getVideoUrl(params);
setLoading(false); setLoading(false);
@ -121,6 +128,10 @@ const CoursePalyPage = () => {
}; };
const initDPlayer = (playUrl: string, isTrySee: number, params: any) => { const initDPlayer = (playUrl: string, isTrySee: number, params: any) => {
let banDrag =
systemConfig.playerIsDisabledDrag && watchRef.current < totalRef.current;
console.log(watchRef.current);
console.log(totalRef.current);
window.player = new window.DPlayer({ window.player = new window.DPlayer({
container: document.getElementById("meedu-player-container"), container: document.getElementById("meedu-player-container"),
autoplay: false, autoplay: false,
@ -139,14 +150,14 @@ const CoursePalyPage = () => {
color: systemConfig.playerBulletSecretColor || "red", color: systemConfig.playerBulletSecretColor || "red",
opacity: Number(systemConfig.playerBulletSecretOpacity), opacity: Number(systemConfig.playerBulletSecretOpacity),
}, },
ban_drag: systemConfig.playerIsDisabledDrag, ban_drag: banDrag,
last_see_pos: params, last_see_pos: params,
}); });
// 监听播放进度更新evt // 监听播放进度更新evt
window.player.on("timeupdate", () => { window.player.on("timeupdate", () => {
let currentTime = parseInt(window.player.video.currentTime); let currentTime = parseInt(window.player.video.currentTime);
if ( if (
systemConfig.playerIsDisabledDrag && banDrag &&
currentTime - playRef.current >= 2 && currentTime - playRef.current >= 2 &&
currentTime > watchRef.current currentTime > watchRef.current
) { ) {
@ -157,10 +168,7 @@ const CoursePalyPage = () => {
} }
}); });
window.player.on("ended", () => { window.player.on("ended", () => {
if ( if (banDrag && window.player.video.duration - playRef.current >= 2) {
systemConfig.playerIsDisabledDrag &&
window.player.video.duration - playRef.current >= 2
) {
window.player.seek(playRef.current); window.player.seek(playRef.current);
return; return;
} }