视频播放根据配置禁止拖动进度条

This commit is contained in:
禺狨 2023-05-30 16:40:10 +08:00
parent 537cac224a
commit 1a9a20cbca
3 changed files with 40 additions and 2 deletions

View File

@ -22,7 +22,11 @@ const CoursePalyPage = () => {
const [loading, setLoading] = useState<Boolean>(false); const [loading, setLoading] = useState<Boolean>(false);
const [isLastpage, setIsLastpage] = useState<Boolean>(false); const [isLastpage, setIsLastpage] = useState<Boolean>(false);
const [totalHours, setTotalHours] = useState<any>([]); const [totalHours, setTotalHours] = useState<any>([]);
const [playingTime, setPlayingTime] = useState(0);
const [watchedSeconds, setWatchedSeconds] = useState(0);
const myRef = useRef(0); const myRef = useRef(0);
const playRef = useRef(0);
const watchRef = useRef(0);
useEffect(() => { useEffect(() => {
getCourse(); getCourse();
@ -45,6 +49,14 @@ const CoursePalyPage = () => {
myRef.current = playDuration; myRef.current = playDuration;
}, [playDuration]); }, [playDuration]);
useEffect(() => {
playRef.current = playingTime;
}, [playingTime]);
useEffect(() => {
watchRef.current = watchedSeconds;
}, [watchedSeconds]);
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 = [];
@ -89,6 +101,7 @@ const CoursePalyPage = () => {
}; };
setLastSeeValue(params); setLastSeeValue(params);
setLastSeeValue(params); setLastSeeValue(params);
setWatchedSeconds(record.finished_duration);
} }
getVideoUrl(params); getVideoUrl(params);
setLoading(false); setLoading(false);
@ -126,14 +139,32 @@ const CoursePalyPage = () => {
color: systemConfig.playerBulletSecretColor || "red", color: systemConfig.playerBulletSecretColor || "red",
opacity: Number(systemConfig.playerBulletSecretOpacity), opacity: Number(systemConfig.playerBulletSecretOpacity),
}, },
ban_drag: false, ban_drag: systemConfig.playerIsDisabledDrag,
last_see_pos: params, last_see_pos: params,
}); });
// 监听播放进度更新evt // 监听播放进度更新evt
window.player.on("timeupdate", () => { 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", () => { window.player.on("ended", () => {
if (
systemConfig.playerIsDisabledDrag &&
window.player.video.duration - playRef.current >= 2
) {
window.player.seek(playRef.current);
return;
}
setPlayingTime(0);
setPlayendedStatus(true); setPlayendedStatus(true);
playTimeUpdate(parseInt(window.player.video.currentTime), true); playTimeUpdate(parseInt(window.player.video.currentTime), true);
window.player && window.player.destroy(); window.player && window.player.destroy();

View File

@ -41,6 +41,11 @@ export const InitPage = (props: Props) => {
props.configData["player-is-enabled-bullet-secret"] === "1" props.configData["player-is-enabled-bullet-secret"] === "1"
? true ? true
: false, : false,
playerIsDisabledDrag:
props.configData["player-disabled-drag"] &&
props.configData["player-disabled-drag"] === "1"
? true
: false,
playerBulletSecretText: props.configData["player-bullet-secret-text"], playerBulletSecretText: props.configData["player-bullet-secret-text"],
playerBulletSecretColor: props.configData["player-bullet-secret-color"], playerBulletSecretColor: props.configData["player-bullet-secret-color"],
playerBulletSecretOpacity: playerBulletSecretOpacity:

View File

@ -9,6 +9,7 @@ type SystemConfigStoreInterface = {
pcIndexFooterMsg: string; pcIndexFooterMsg: string;
playerPoster: string; playerPoster: string;
playerIsEnabledBulletSecret: boolean; playerIsEnabledBulletSecret: boolean;
playerIsDisabledDrag: boolean;
playerBulletSecretText: string; playerBulletSecretText: string;
playerBulletSecretColor: string; playerBulletSecretColor: string;
playerBulletSecretOpacity: string; playerBulletSecretOpacity: string;
@ -23,6 +24,7 @@ let defaultValue: SystemConfigStoreInterface = {
pcIndexFooterMsg: "", pcIndexFooterMsg: "",
playerPoster: "", playerPoster: "",
playerIsEnabledBulletSecret: false, playerIsEnabledBulletSecret: false,
playerIsDisabledDrag: false,
playerBulletSecretText: "", playerBulletSecretText: "",
playerBulletSecretColor: "", playerBulletSecretColor: "",
playerBulletSecretOpacity: "", playerBulletSecretOpacity: "",