MCPcopy Create free account
hub / github.com/triggerdotdev/jsonhero-web / AutoplayVideo

Function AutoplayVideo

app/components/AutoplayVideo.tsx:4–30  ·  view source on GitHub ↗
({ src }: { src: string })

Source from the content-addressed store, hash-verified

2import { useOnScreen } from "~/hooks/useOnScreen";
3
4export function AutoplayVideo({ src }: { src: string }) {
5 const elementRef = useRef<HTMLVideoElement>(null);
6 const isOnScreen = useOnScreen(elementRef);
7
8 useEffect(() => {
9 if (elementRef.current == null) return;
10
11 elementRef.current.muted = true;
12 elementRef.current.playsInline = true;
13
14 if (isOnScreen) {
15 elementRef.current.play();
16 } else {
17 elementRef.current.pause();
18 }
19 }, [isOnScreen]);
20
21 return (
22 <video
23 src={src}
24 ref={elementRef}
25 loop={true}
26 muted={true}
27 autoPlay={false}
28 />
29 );
30}

Callers

nothing calls this directly

Calls 1

useOnScreenFunction · 0.90

Tested by

no test coverage detected