diff --git a/src/player/components/PlayerIframe.tsx b/src/player/components/PlayerIframe.tsx index 877ede4..88463db 100644 --- a/src/player/components/PlayerIframe.tsx +++ b/src/player/components/PlayerIframe.tsx @@ -7,12 +7,20 @@ interface PlayerIframeProps { } export default function PlayerIframe({ videoSrc, onNextVideo, isPlaying }: PlayerIframeProps) { - const iframeRef = useRef(null); + const iframeRef = useRef(null); const isPlayingRef = useRef(isPlaying); const onNextVideoRef = useRef(onNextVideo); const [time, setTime] = useState({ current: 0, duration: 0 }); + // iframe 랜더링 시 이벤트 등록 + const setIframeRef = (node: HTMLIFrameElement | null) => { + iframeRef.current = node; + if (node) { + node.addEventListener('load', loadEventListener); + } + }; + useEffect(() => { const interval = setInterval(() => { const video = getVideoElement(); @@ -54,7 +62,7 @@ export default function PlayerIframe({ videoSrc, onNextVideo, isPlaying }: Playe }; // load 이벤트 시 video listener 세팅 - const attachVideoListeners = () => { + const loadEventListener = () => { const video = getVideoElement(); if (!video) return; @@ -69,8 +77,8 @@ export default function PlayerIframe({ videoSrc, onNextVideo, isPlaying }: Playe useEffect(() => { const iframe = iframeRef.current; if (!iframe) return; - iframe.addEventListener('load', attachVideoListeners); - return () => iframe.removeEventListener('load', attachVideoListeners); + iframe.addEventListener('load', loadEventListener); + return () => iframe.removeEventListener('load', loadEventListener); }, [videoSrc]); // isPlaying 변경 시 재생 상태 제어 @@ -89,38 +97,49 @@ export default function PlayerIframe({ videoSrc, onNextVideo, isPlaying }: Playe }, []); return ( -
-
- {time.duration > 0 ? ( -
- - {Math.floor(time.current / 60)}: - {Math.floor(time.current % 60) - .toString() - .padStart(2, '0')}{' '} - - / - - {Math.floor(time.duration / 60)}: - {Math.floor(time.duration % 60) - .toString() - .padStart(2, '0')} - -
+
+
+ {isPlaying ? ( + time.duration > 0 ? ( +
+ + {Math.floor(time.current / 60)}: + {Math.floor(time.current % 60) + .toString() + .padStart(2, '0')}{' '} + + / + + {Math.floor(time.duration / 60)}: + {Math.floor(time.duration % 60) + .toString() + .padStart(2, '0')} + +
+ ) : ( +
영상 정보가 없습니다
+ ) ) : ( -
영상 정보가 없습니다
+
+ 자동수강을 시작하려면 수강시작 버튼을 눌러주세요 +
)}
-