diff --git a/frontend/src/b/Shorts.tsx b/frontend/src/b/Shorts.tsx index d116d03..9e7e9f4 100644 --- a/frontend/src/b/Shorts.tsx +++ b/frontend/src/b/Shorts.tsx @@ -102,13 +102,15 @@ function ShortCard({ s, playing, onOpen }: { s: ShortItem; playing: boolean; onO /** * 전체 화면 재생 창: 네이티브 라 ESC·포커스 가두기가 기본. - * 넘길 때 검은 화면이 보이지 않게 앞뒤 영상도 소리 없이 틀어 첫 장면을 받아 둔 뒤 멈춰 두고, 보이는 것만 처음부터 재생한다 + * 처음 열 때·넘길 때 검은 화면이 보이지 않게, 첫 장면을 받을 때까지는 표지를 보이고 앞뒤 영상도 소리 없이 틀어 첫 장면을 받아 둔 뒤 멈춰 두고, 보이는 것만 처음부터 재생한다 */ function ShortsViewer({ items, start, onClose }: { items: ShortItem[]; start: number; onClose: () => void }) { const dialog = useRef(null) const list = useRef(null) const [at, setAt] = useState(start) const [sound, setSound] = useState(false) + // 첫 장면을 받은 플레이어. 그 전엔 플레이어의 검은 화면 대신 표지를 보인다 + const [ready, setReady] = useState>(new Set()) const frames = useRef(new Map()) const atRef = useRef(start) const soundRef = useRef(false) @@ -151,7 +153,9 @@ function ShortsViewer({ items, start, onClose }: { items: ShortItem[]; start: nu } if (msg.info?.playerState !== PLAYING) return for (const [i, f] of frames.current) { - if (f.contentWindow !== e.source || i === atRef.current) continue + if (f.contentWindow !== e.source) continue + setReady((r) => (r.has(i) ? r : new Set(r).add(i))) + if (i === atRef.current) continue command(f, 'pauseVideo') command(f, 'seekTo', [0, true]) } @@ -205,8 +209,17 @@ function ShortsViewer({ items, start, onClose }: { items: ShortItem[]; start: nu title={s.title} allow="autoplay; encrypted-media; picture-in-picture" // 재생 상태를 받으려면 플레이어에 먼저 '듣고 있다'고 알린다 - onLoad={(e) => e.currentTarget.contentWindow?.postMessage(JSON.stringify({ event: 'listening', id: s.id }), YT_ORIGIN)} - className="absolute inset-0 size-full border-0" + onLoad={(e) => { + e.currentTarget.contentWindow?.postMessage(JSON.stringify({ event: 'listening', id: s.id }), YT_ORIGIN) + // 앞뒤 밖으로 밀려나 내려갔다 다시 뜬 플레이어는 첫 장면을 새로 받을 때까지 다시 숨긴다 + setReady((r) => { + if (!r.has(i)) return r + const next = new Set(r) + next.delete(i) + return next + }) + }} + className={cx('absolute inset-0 size-full border-0 transition-opacity duration-200', !ready.has(i) && 'opacity-0')} /> )}