From 6913cc6abcdcefc5454711a601bb0c97508de043 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Tue, 28 May 2024 07:11:23 -0600 Subject: [PATCH] Handle case where preview doesn't automatically changeover (#11583) --- web/src/components/player/PreviewPlayer.tsx | 29 +++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/web/src/components/player/PreviewPlayer.tsx b/web/src/components/player/PreviewPlayer.tsx index a5f3f771c..9275101b8 100644 --- a/web/src/components/player/PreviewPlayer.tsx +++ b/web/src/components/player/PreviewPlayer.tsx @@ -197,6 +197,7 @@ function PreviewVideoPlayer({ const canvasRef = useRef(null); const [videoSize, setVideoSize] = useState([0, 0]); + const [changeoverTimeout, setChangeoverTimeout] = useState(); const changeSource = useCallback( (newPreview: Preview | undefined, video: HTMLVideoElement | null) => { @@ -220,6 +221,15 @@ function PreviewVideoPlayer({ } setCurrentPreview(newPreview); + const timeout = setTimeout(() => { + if (timeout) { + clearTimeout(timeout); + setChangeoverTimeout(undefined); + } + + previewRef.current?.load(); + }, 1000); + setChangeoverTimeout(timeout); // we only want this to change when current preview changes // eslint-disable-next-line react-hooks/exhaustive-deps @@ -243,6 +253,7 @@ function PreviewVideoPlayer({ ); if (preview != currentPreview) { + controller.newPreviewLoaded = false; changeSource(preview, previewRef.current); } @@ -267,7 +278,14 @@ function PreviewVideoPlayer({ previewRef.current?.load()} + onLoad={() => { + if (changeoverTimeout) { + clearTimeout(changeoverTimeout); + setChangeoverTimeout(undefined); + } + + previewRef.current?.load(); + }} />