This commit is contained in:
Fredrik Burmester
2024-10-15 08:01:12 +02:00
parent 13d4117cc1
commit ae963751cf
7 changed files with 790 additions and 248 deletions

View File

@@ -21,7 +21,8 @@ interface CreditTimestamps {
export const useCreditSkipper = (
itemId: string | undefined,
currentTime: number,
videoRef: React.RefObject<any>
seek: (time: number) => void,
play: () => void
) => {
const [api] = useAtom(apiAtom);
const [showSkipCreditButton, setShowSkipCreditButton] = useState(false);
@@ -60,16 +61,16 @@ export const useCreditSkipper = (
}, [creditTimestamps, currentTime]);
const skipCredit = useCallback(() => {
if (!creditTimestamps || !videoRef.current) return;
if (!creditTimestamps) return;
try {
videoRef.current.seek(creditTimestamps.Credits.End);
seek(creditTimestamps.Credits.End);
setTimeout(() => {
videoRef.current?.resume();
play();
}, 200);
} catch (error) {
writeToLog("ERROR", "Error skipping intro", error);
}
}, [creditTimestamps, videoRef]);
}, [creditTimestamps]);
return { showSkipCreditButton, skipCredit };
};

View File

@@ -17,7 +17,8 @@ interface IntroTimestamps {
export const useIntroSkipper = (
itemId: string | undefined,
currentTime: number,
videoRef: React.RefObject<any>
seek: (ticks: number) => void,
play: () => void
) => {
const [api] = useAtom(apiAtom);
const [showSkipButton, setShowSkipButton] = useState(false);
@@ -57,16 +58,16 @@ export const useIntroSkipper = (
const skipIntro = useCallback(() => {
console.log("skipIntro");
if (!introTimestamps || !videoRef.current) return;
if (!introTimestamps) return;
try {
videoRef.current.seek(introTimestamps.IntroEnd);
seek(introTimestamps.IntroEnd);
setTimeout(() => {
videoRef.current?.resume();
play();
}, 200);
} catch (error) {
writeToLog("ERROR", "Error skipping intro", error);
}
}, [introTimestamps, videoRef]);
}, [introTimestamps]);
return { showSkipButton, skipIntro };
};