diff --git a/web/src/components/player/PreviewPlayer.tsx b/web/src/components/player/PreviewPlayer.tsx index 6c4a5a479..1ec2a9bcd 100644 --- a/web/src/components/player/PreviewPlayer.tsx +++ b/web/src/components/player/PreviewPlayer.tsx @@ -134,6 +134,7 @@ function PreviewVideoPlayer({ // initial state const [loaded, setLoaded] = useState(false); + const [hasCanvas, setHasCanvas] = useState(false); const initialPreview = useMemo(() => { return cameraPreviews.find( (preview) => @@ -187,22 +188,51 @@ function PreviewVideoPlayer({ // eslint-disable-next-line react-hooks/exhaustive-deps }, [controller, timeRange]); + // canvas to cover preview transition + + const canvasRef = useRef(null); + const [videoWidth, videoHeight] = useMemo(() => { + if (!previewRef.current) { + return [0, 0]; + } + + return [previewRef.current.videoWidth, previewRef.current.videoHeight]; + // we know the video size will be known on load + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [loaded]); + // handle switching sources + useEffect(() => { if (!currentPreview || !previewRef.current) { return; } + if (canvasRef.current) { + canvasRef.current + .getContext("2d") + ?.drawImage(previewRef.current, 0, 0, videoWidth, videoHeight); + setHasCanvas(true); + } + previewRef.current.load(); + // we only want this to change when current preview changes + // eslint-disable-next-line react-hooks/exhaustive-deps }, [currentPreview, previewRef]); return (
+ - {!loaded && } + {!loaded && !hasCanvas && } {cameraPreviews && !currentPreview && (
No Preview Found