From 7ffeecbb4fdbb19e282a4fe3fe964739523bf719 Mon Sep 17 00:00:00 2001 From: Mina Choi Date: Tue, 27 Oct 2026 19:22:26 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=ED=86=A0=EC=8A=A4=ED=8C=90=20=EC=87=BC?= =?UTF-8?q?=EC=B8=A0=EB=8F=84=20=EB=A6=B4=EC=8A=A4=EC=B2=98=EB=9F=BC=20?= =?UTF-8?q?=EB=8B=A4=EC=9D=8C=20=EC=98=81=EC=83=81=EC=9D=84=20=EB=AF=B8?= =?UTF-8?q?=EB=A6=AC=20=EB=B0=9B=EC=95=84=20=EB=91=A0=20=E2=80=94=20?= =?UTF-8?q?=EB=8B=A4=EC=9D=8C=20=EC=98=81=EC=83=81=EC=9D=80=20=EB=A9=88?= =?UTF-8?q?=EC=B6=98=20=EC=B1=84=20=EB=9D=84=EC=9B=8C=20=EB=91=90=EA=B3=A0?= =?UTF-8?q?=20=EB=84=98=EC=96=B4=EC=98=A4=EB=A9=B4=20=EC=9E=AC=EC=83=9D,?= =?UTF-8?q?=20=EC=A7=80=EB=82=9C=20=EC=98=81=EC=83=81=EC=9D=80=20=EB=82=B4?= =?UTF-8?q?=EB=A0=A4=20=EC=86=8C=EB=A6=AC=EA=B0=80=20=EA=B2=B9=EC=B9=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EA=B2=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/b/Shorts.tsx | 55 ++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/frontend/src/b/Shorts.tsx b/frontend/src/b/Shorts.tsx index 1026368..0661107 100644 --- a/frontend/src/b/Shorts.tsx +++ b/frontend/src/b/Shorts.tsx @@ -43,9 +43,9 @@ const PLAIN = IS_TOSS // 토스는 재생 상태가 안 오므로, 플레이어 문서가 뜨고 이만큼 지나면 첫 장면이 나왔다고 보고 표지를 걷는다 (그 전엔 플레이어의 검은 화면 대신 표지) const PLAIN_SHOW_MS = 1000 -function embed(id: string, plain = false) { +function embed(id: string, plain = false, autoplay = true) { const q = new URLSearchParams({ - autoplay: '1', mute: plain ? '0' : '1', playsinline: '1', loop: '1', playlist: id, controls: plain ? '1' : '0', rel: '0', modestbranding: '1', + autoplay: autoplay ? '1' : '0', mute: plain ? '0' : '1', playsinline: '1', loop: '1', playlist: id, controls: plain ? '1' : '0', rel: '0', modestbranding: '1', enablejsapi: '1', origin: window.location.origin, }) return `${YT_ORIGIN}/embed/${id}?${q}` @@ -153,10 +153,24 @@ 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 [plainShown, setPlainShown] = useState>(new Set()) + const plainTimers = useRef(new Set()) + useEffect(() => { + const timers = plainTimers.current + return () => timers.forEach((t) => window.clearTimeout(t)) + }, []) + // 토스: 플레이어마다 처음 띄울 때 지금 영상이면 자동재생, 미리 받아 두는 다음 영상은 멈춘 채로. 한 번 정하면 주소가 바뀌어 다시 받지 않게 기억한다 + const [plainAutoplay, setPlainAutoplay] = useState>(() => new Map([[start, true], [start + 1, false]])) + /** 지금 영상이 n 으로 바뀔 때: 새로 띄울 지금 영상은 자동재생, 다음 영상은 멈춘 채로 (이미 띄운 것은 그대로) */ + const keepAutoplay = (n: number) => + setPlainAutoplay((m) => { + const next = new Map([...m].filter(([i]) => i === n || i === n + 1)) + if (!next.has(n)) next.set(n, true) + if (!next.has(n + 1)) next.set(n + 1, false) + return next + }) + const autoplayOnMount = (i: number) => plainAutoplay.get(i) ?? i === at const frames = useRef(new Map()) const atRef = useRef(start) const soundRef = useRef(false) @@ -188,7 +202,12 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta if (!box) return const io = new IntersectionObserver( (entries) => { - for (const e of entries) if (e.isIntersecting) setAt(Number((e.target as HTMLElement).dataset.i)) + for (const e of entries) { + if (!e.isIntersecting) continue + const n = Number((e.target as HTMLElement).dataset.i) + setAt(n) + if (PLAIN) keepAutoplay(n) + } }, { root: box, threshold: 0.6 }, ) @@ -224,14 +243,14 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta if (atRef.current !== at) moved(items[at]) atRef.current = at paused.current = false - if (PLAIN) return for (const [i, f] of frames.current) { + // 토스는 소리를 켠 채 유튜브 기본 플레이어로 두므로 재생·멈춤만 (소리 명령 없음) if (i === at) { - command(f, soundRef.current ? 'unMute' : 'mute') + if (!PLAIN) command(f, soundRef.current ? 'unMute' : 'mute') command(f, 'playVideo') } else { command(f, 'pauseVideo') - command(f, 'mute') + if (!PLAIN) command(f, 'mute') } } }, [at, items]) @@ -330,20 +349,26 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta
- {(PLAIN ? i === at : Math.abs(i - at) <= 1) && ( + {/* 릴스처럼 다음 영상을 미리 받아 둔다. 토스는 재생 상태가 안 와 멈추게 할 수 없을 수 있어, 지난 영상은 내려 소리가 겹치지 않게 지금·다음만 */} + {(PLAIN ? i === at || i === at + 1 : Math.abs(i - at) <= 1) && (