diff --git a/frontend/src/b/Shorts.tsx b/frontend/src/b/Shorts.tsx index 0661107..eb12f3d 100644 --- a/frontend/src/b/Shorts.tsx +++ b/frontend/src/b/Shorts.tsx @@ -37,15 +37,14 @@ function useTabBarHeight() { const YT_ORIGIN = 'https://www.youtube-nocookie.com' -// 토스 웹뷰에는 플레이어가 보내는 재생 상태가 오지 않아, 쇼츠 페이지는 플레이어를 숨기거나 명령하지 않고 유튜브 기본 조작(재생 버튼)과 소리를 켠 채 그대로 보인다. -// 영상 위 터치는 유튜브가 가져가므로 넘기기는 버튼으로 +// 토스 웹뷰에는 플레이어가 보내는 재생 상태가 오지 않는다. 그래서 토스는 첫 장면이 나왔는지를 시간으로 보고 표지를 걷는다 (나머지는 웹과 같다) const PLAIN = IS_TOSS // 토스는 재생 상태가 안 오므로, 플레이어 문서가 뜨고 이만큼 지나면 첫 장면이 나왔다고 보고 표지를 걷는다 (그 전엔 플레이어의 검은 화면 대신 표지) const PLAIN_SHOW_MS = 1000 -function embed(id: string, plain = false, autoplay = true) { +function embed(id: string) { const q = new URLSearchParams({ - autoplay: autoplay ? '1' : '0', mute: plain ? '0' : '1', playsinline: '1', loop: '1', playlist: id, controls: plain ? '1' : '0', rel: '0', modestbranding: '1', + autoplay: '1', mute: '1', playsinline: '1', loop: '1', playlist: id, controls: '0', rel: '0', modestbranding: '1', enablejsapi: '1', origin: window.location.origin, }) return `${YT_ORIGIN}/embed/${id}?${q}` @@ -160,17 +159,6 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta 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) @@ -202,12 +190,7 @@ 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) continue - const n = Number((e.target as HTMLElement).dataset.i) - setAt(n) - if (PLAIN) keepAutoplay(n) - } + for (const e of entries) if (e.isIntersecting) setAt(Number((e.target as HTMLElement).dataset.i)) }, { root: box, threshold: 0.6 }, ) @@ -244,13 +227,12 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta atRef.current = at paused.current = false for (const [i, f] of frames.current) { - // 토스는 소리를 켠 채 유튜브 기본 플레이어로 두므로 재생·멈춤만 (소리 명령 없음) if (i === at) { - if (!PLAIN) command(f, soundRef.current ? 'unMute' : 'mute') + command(f, soundRef.current ? 'unMute' : 'mute') command(f, 'playVideo') } else { command(f, 'pauseVideo') - if (!PLAIN) command(f, 'mute') + command(f, 'mute') } } }, [at, items]) @@ -295,10 +277,6 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta box.scrollTo({ top: target * h, behavior: 'smooth' }) } - const go = (step: number) => { - const box = list.current - if (box) box.scrollTo({ top: (at + step) * box.clientHeight, behavior: 'smooth' }) - } const toggleSound = () => { const on = !sound @@ -329,34 +307,23 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta - {PLAIN ? ( -
- - -
- ) : ( - - )} +
{items.map((s, i) => (
- {/* 릴스처럼 다음 영상을 미리 받아 둔다. 토스는 재생 상태가 안 와 멈추게 할 수 없을 수 있어, 지난 영상은 내려 소리가 겹치지 않게 지금·다음만 */} - {(PLAIN ? i === at || i === at + 1 : Math.abs(i - at) <= 1) && ( + {/* 릴스처럼 앞뒤 영상을 소리 없이 미리 받아 둔다 */} + {Math.abs(i - at) <= 1 && (