From 74805aa829abe90e580a442e23b25f922d16a17b Mon Sep 17 00:00:00 2001 From: Mina Choi Date: Tue, 27 Oct 2026 19:56:06 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=87=BC=EC=B8=A0=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EB=A9=88=EC=B6=A4=20=EB=AA=85=EB=A0=B9=EC=9D=84=20=EC=97=86?= =?UTF-8?q?=EC=95=B0=20=E2=80=94=20=EC=95=9E=EB=92=A4=20=EC=98=81=EC=83=81?= =?UTF-8?q?=EC=9D=80=20=EC=86=8C=EB=A6=AC=20=EC=97=86=EC=9D=B4=20=EA=B3=84?= =?UTF-8?q?=EC=86=8D=20=ED=8B=80=EC=96=B4=20=EB=91=90=EA=B3=A0=20=EB=84=98?= =?UTF-8?q?=EC=96=B4=EC=98=A4=EB=A9=B4=20=EC=B2=98=EC=9D=8C=EB=B6=80?= =?UTF-8?q?=ED=84=B0,=20=ED=86=A1=20=EB=88=84=EB=A5=B4=EB=A9=B4=20?= =?UTF-8?q?=EB=A6=B4=EC=8A=A4=EC=B2=98=EB=9F=BC=20=EC=86=8C=EB=A6=AC=20?= =?UTF-8?q?=EC=BC=9C=EA=B8=B0=C2=B7=EB=81=84=EA=B8=B0=20(=EB=A9=88?= =?UTF-8?q?=EC=B7=84=EB=8B=A4=20=ED=8B=80=EB=A9=B4=20=EC=9C=A0=ED=8A=9C?= =?UTF-8?q?=EB=B8=8C=EA=B0=80=20=EC=9E=AC=EC=83=9D=C2=B7=EB=A9=88=EC=B6=A4?= =?UTF-8?q?=20=EB=B2=84=ED=8A=BC=EC=9D=84=20=EB=9D=84=EC=9B=8C=EC=84=9C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/b/Shorts.tsx | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/frontend/src/b/Shorts.tsx b/frontend/src/b/Shorts.tsx index d48ed29..9555a03 100644 --- a/frontend/src/b/Shorts.tsx +++ b/frontend/src/b/Shorts.tsx @@ -50,7 +50,7 @@ function embed(id: string) { return `${YT_ORIGIN}/embed/${id}?${q}` } -type Func = 'playVideo' | 'pauseVideo' | 'seekTo' | 'mute' | 'unMute' +type Func = 'playVideo' | 'seekTo' | 'mute' | 'unMute' /** 이미 띄운 플레이어에 명령 (IFrame API 메시지) */ function command(frame: HTMLIFrameElement | null | undefined, func: Func, args: unknown[] = []) { @@ -181,8 +181,6 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta const frames = useRef(new Map()) const atRef = useRef(start) const soundRef = useRef(false) - // 누르기로 멈춘 상태. 다른 영상으로 넘어가면 다시 재생 중으로 - const paused = useRef(false) // 처음 한 번: 시작 영상으로 맞추고, 뒤 페이지 스크롤을 잠근다 const startRef = useRef(start) @@ -217,7 +215,7 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta return () => io.disconnect() }, []) - // 미리 띄운 영상이 재생되기 시작하면(첫 장면을 받음) 보이는 영상이 아닐 때 멈추고 처음으로 + // 플레이어가 재생을 시작하면(첫 장면을 받음) 보이게 한다. 앞뒤 영상은 멈추지 않는다: 멈췄다 다시 틀면 유튜브가 재생·멈춤 버튼을 영상 위에 띄운다 useEffect(() => { const onMessage = (e: MessageEvent) => { if (e.origin !== YT_ORIGIN || typeof e.data !== 'string') return @@ -231,9 +229,6 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta for (const [i, f] of frames.current) { 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]) } } window.addEventListener('message', onMessage) @@ -244,27 +239,21 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta useEffect(() => { if (atRef.current !== at) moved(items[at]) atRef.current = at - paused.current = false + // 앞뒤 영상은 소리 없이 계속 돌고 있으니, 넘어온 영상만 처음부터 다시 틀고 소리를 맞춘다 (멈춤 명령은 쓰지 않는다) for (const [i, f] of frames.current) { if (i === at) { + command(f, 'seekTo', [0, true]) command(f, soundRef.current ? 'unMute' : 'mute') command(f, 'playVideo') - } else { - command(f, 'pauseVideo') - command(f, 'mute') - } + } else command(f, 'mute') } }, [at, items]) // 마우스로도 끌어 넘긴다: 영상 위는 유튜브 iframe 이 마우스를 가져가서, 그 위에 투명한 판을 깔고 끈 만큼 목록을 옮긴다. - // 손가락은 브라우저 스크롤에 맡기고, 끌지 않고 누르기만 하면 재생·일시정지 + // 손가락은 브라우저 스크롤에 맡기고, 끌지 않고 누르기만 하면 릴스처럼 소리 켜기·끄기 (멈추면 유튜브 버튼이 떠서) const drag = useRef<{ y: number; top: number; moved: boolean } | null>(null) const lastPointer = useRef('') const [dragging, setDragging] = useState(false) - const togglePause = () => { - paused.current = !paused.current - command(frames.current.get(atRef.current), paused.current ? 'pauseVideo' : 'playVideo') - } const onPointerDown = (e: ReactPointerEvent) => { lastPointer.current = e.pointerType const box = list.current @@ -287,7 +276,7 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta drag.current = null setDragging(false) if (!d || !box) return - if (!d.moved) return togglePause() + if (!d.moved) return toggleSound() // 30px 만 끌어도 다음·이전 영상으로, 그보다 덜 끌면 제자리로 const h = box.clientHeight const dy = e.clientY - d.y @@ -374,7 +363,7 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta drag.current = null setDragging(false) }} - onClick={() => lastPointer.current !== 'mouse' && togglePause()} + onClick={() => lastPointer.current !== 'mouse' && toggleSound()} className={cx('absolute inset-0 touch-pan-y select-none', dragging ? 'cursor-grabbing' : 'cursor-grab')} />