From 655ecee82ae1bd0114154b69e8585def1306557b Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 12 May 2021 17:48:43 +0200 Subject: video timer / frame counter --- pages/present.tsx | 52 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/pages/present.tsx b/pages/present.tsx index b0b020e..7254594 100644 --- a/pages/present.tsx +++ b/pages/present.tsx @@ -22,6 +22,10 @@ export default function Present() { }, []); var [ videoSRC, setVideoSRC ] = useState(""); + var [ slides, setSlides ] = useState(); + + var precision = 3; + var framerate = 60; useEffect(() => { var videoEL = document.getElementById("player") as HTMLVideoElement; @@ -29,9 +33,18 @@ export default function Present() { console.log("initial load") }) videoEL.addEventListener('canplaythrough', () => { - console.log("full load") videoEL.play(); }) + + setInterval(() => { + if(videoEL.paused) return; + var frame = Math.round((videoEL.currentTime * 1e3) / (1e3 / framerate)); + document.getElementById('frame').innerText = frame.toString(); + if (frame >= framerate) { + videoEL.pause() + console.log(videoEL.currentTime) + }; + }, 1e3 / (precision * framerate)); }, []); return
@@ -71,17 +84,46 @@ export default function Present() { reader.readAsDataURL(file); }} /> -