import type {PlayerRef} from '@remotion/player'; import {Player} from '@remotion/player'; import React, {useCallback, useEffect, useRef, useState} from 'react'; import {ColorDemo} from './ColorDemo'; import './input-fields.css'; export const PlayerExample: React.FC<{ readonly name: string; readonly color: string; readonly autoPlayOnFocus?: boolean; }> = ({name, color}) => { const containerRef = useRef(null); const playerRef = useRef(null); const [isIntersecting, setIsIntersecting] = useState(false); const callback: IntersectionObserverCallback = useCallback( (newData) => { setIsIntersecting(newData[0].isIntersecting); if (isIntersecting) { playerRef.current?.play(); } else { playerRef.current?.pause(); } }, [isIntersecting], ); useEffect(() => { const {current} = containerRef; if (!current) { return; } const observer = new IntersectionObserver(callback, { root: null, threshold: 1, }); observer.observe(current); return () => observer.unobserve(current); }, [callback]); return (
); };