diff --git a/frontend/src/b/Shorts.tsx b/frontend/src/b/Shorts.tsx index bfbf95f..aab80b0 100644 --- a/frontend/src/b/Shorts.tsx +++ b/frontend/src/b/Shorts.tsx @@ -34,6 +34,8 @@ const YT_ORIGIN = 'https://www.youtube-nocookie.com' // 토스 웹뷰에는 플레이어가 보내는 재생 상태가 오지 않아, 쇼츠 페이지는 플레이어를 숨기거나 명령하지 않고 유튜브 기본 조작(재생 버튼)과 소리를 켠 채 그대로 보인다. // 영상 위 터치는 유튜브가 가져가므로 넘기기는 버튼으로 const PLAIN = IS_TOSS +// 토스는 재생 상태가 안 오므로, 플레이어 문서가 뜨고 이만큼 지나면 첫 장면이 나왔다고 보고 표지를 걷는다 (그 전엔 플레이어의 검은 화면 대신 표지) +const PLAIN_SHOW_MS = 1000 function embed(id: string, plain = false) { const q = new URLSearchParams({ @@ -144,6 +146,10 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta const tabH = useTabBarHeight() // 첫 장면을 받은 플레이어. 그 전엔 플레이어의 검은 화면 대신 표지를 보인다 const [ready, setReady] = useState>(new Set()) + // 토스: 표지를 걷은 플레이어 번호 (하나만 띄우므로 하나) + const [plainShownAt, setPlainShownAt] = useState(-1) + const plainTimer = useRef(0) + useEffect(() => () => window.clearTimeout(plainTimer.current), []) const frames = useRef(new Map()) const atRef = useRef(start) const soundRef = useRef(false) @@ -327,6 +333,10 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta allow="autoplay; encrypted-media; picture-in-picture" // 재생 상태를 받으려면 플레이어에 먼저 '듣고 있다'고 알린다 onLoad={(e) => { + if (PLAIN) { + window.clearTimeout(plainTimer.current) + plainTimer.current = window.setTimeout(() => setPlainShownAt(i), PLAIN_SHOW_MS) + } e.currentTarget.contentWindow?.postMessage(JSON.stringify({ event: 'listening', id: s.id }), YT_ORIGIN) // 앞뒤 밖으로 밀려나 내려갔다 다시 뜬 플레이어는 첫 장면을 새로 받을 때까지 다시 숨긴다 setReady((r) => { @@ -336,7 +346,7 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta return next }) }} - className={cx('absolute inset-0 size-full border-0 transition-opacity duration-200', !PLAIN && !ready.has(i) && 'opacity-0')} + className={cx('absolute inset-0 size-full border-0 transition-opacity duration-200', (PLAIN ? plainShownAt !== i : !ready.has(i)) && 'opacity-0')} /> )} {!PLAIN && (