From c9b1cb51efcbf2ca47bdbf64f3972023d6934c23 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 13 May 2021 21:42:32 +0200 Subject: rerender slides thingy's --- pages/present.tsx | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) (limited to 'pages') diff --git a/pages/present.tsx b/pages/present.tsx index f4dd486..1e37702 100644 --- a/pages/present.tsx +++ b/pages/present.tsx @@ -1,7 +1,7 @@ import Button from '@material-ui/core/Button'; import Ajv from 'ajv'; -import { useEffect } from 'react'; -import timeline, { slide, anySlide } from '../timeline'; +import { useEffect, useState } from 'react'; +import timeline, { delaySlide, loopSlide, slide, speedChangeSlide } from '../timeline'; import * as timelineSchema from '../timeline.schema.json'; import ExitToAppRoundedIcon from '@material-ui/icons/ExitToAppRounded'; @@ -54,10 +54,10 @@ class TimedVideoPlayer { this.player.pause(); } - handleSlide(slide: anySlide) { - switch(slide.type) { + handleSlide(slide: slide) { + switch (slide.type) { case 'loop': { - this.jumpToFrame(slide.beginFrame); + this.jumpToFrame((slide as loopSlide).beginFrame); break; } case 'delay': { @@ -65,12 +65,12 @@ class TimedVideoPlayer { this.slide++; setTimeout(() => { this.player.play(); - }, slide.delay); + }, (slide as delaySlide).delay); break; } case 'speedChange': { this.slide++; - this.player.playbackRate = this.framerate / slide.newFramerate; + this.player.playbackRate = this.framerate / (slide as speedChangeSlide).newFramerate; break; } default: { @@ -97,8 +97,9 @@ class TimedVideoPlayer { var slide = this.timeline.slides[this.slide]; if (!slide) return; - if (this.frame >= slide.frame) + if (this.frame >= slide.frame) { this.handleSlide(slide); + } }, 1e3 / (this.precision * this.framerate)); this.registeredEventListeners = true; @@ -169,14 +170,16 @@ class TimedVideoPlayer { } export default function Present() { + var [dummy, setDummy] = useState(false); + var rerender = () => setDummy(!dummy); + var [player, setPlayer] = useState(new TimedVideoPlayer()); + useEffect(() => { setInterval(() => { document.getElementById('time').innerText = new Date().toLocaleTimeString(); }, 500); }, []); - var player = new TimedVideoPlayer(); - useEffect(() => { var videoEL = document.getElementById('player') as HTMLVideoElement; player.registerPlayer(videoEL); @@ -191,14 +194,26 @@ export default function Present() {
-
player.previous()}/> +
{ + player.previous(); + rerender(); + }} + />
{ document.getElementById('menu').classList.add('active'); }} /> -
player.next()} /> +
{ + player.next(); + rerender(); + }} + />
-

slide 1/15

+

+ slide {player.slide + 1}/{player.timeline?.slides.length || 0} +

-- cgit v1.2.3