fix: 쇼츠 창을 처음 열 때 검은 플레이어가 깜빡이던 문제 — 첫 장면이 재생될 때까지 표지를 보이고 플레이어는 그 뒤에 서서히 띄움

This commit is contained in:
minaChoi committed 2026-10-26 14:40:10 +09:00
1 parent b4d09574da
commit 9adee6762e
1 file changed
+17 -4
+17 -4
View File
@@ -102,13 +102,15 @@ function ShortCard({ s, playing, onOpen }: { s: ShortItem; playing: boolean; onO
/**
* 전체 화면 재생 창: 네이티브 <dialog>라 ESC·포커스 가두기가 기본.
* 넘길 때 검은 화면이 보이지 않게 앞뒤 영상도 소리 없이 틀어 첫 장면을 받아 둔 뒤 멈춰 두고, 보이는 것만 처음부터 재생한다
* 처음 열 때·넘길 때 검은 화면이 보이지 않게, 첫 장면을 받을 때까지는 표지를 보이고 앞뒤 영상도 소리 없이 틀어 첫 장면을 받아 둔 뒤 멈춰 두고, 보이는 것만 처음부터 재생한다
*/
function ShortsViewer({ items, start, onClose }: { items: ShortItem[]; start: number; onClose: () => void }) {
const dialog = useRef<HTMLDialogElement>(null)
const list = useRef<HTMLDivElement>(null)
const [at, setAt] = useState(start)
const [sound, setSound] = useState(false)
// 첫 장면을 받은 플레이어. 그 전엔 플레이어의 검은 화면 대신 표지를 보인다
const [ready, setReady] = useState<ReadonlySet<number>>(new Set())
const frames = useRef(new Map<number, HTMLIFrameElement>())
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')}
/>
)}
</div>