({ src }: { src: string })
| 2 | import { useOnScreen } from "~/hooks/useOnScreen"; |
| 3 | |
| 4 | export 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 | } |
nothing calls this directly
no test coverage detected