diff --git a/src/app/play/page.tsx b/src/app/play/page.tsx index b57e798..3f6ac30 100644 --- a/src/app/play/page.tsx +++ b/src/app/play/page.tsx @@ -75,6 +75,56 @@ function PlayPageClient() { const [reverseEpisodeOrder, setReverseEpisodeOrder] = useState(false); const shortcutHintTimeoutRef = useRef(null); + // NEW STATE: 控制快进/快退按钮是否显示 + const [showSkipButtons, setShowSkipButtons] = useState(true); + + // 使用 ResizeObserver 根据 MediaPlayer 元素尺寸动态决定按钮显隐 + useEffect(() => { + if ( + typeof window === 'undefined' || + typeof ResizeObserver === 'undefined' + ) { + return; + } + + const updateShowSkipButtons = () => { + const el: HTMLElement | undefined = (playerRef.current as any)?.el; + if (!el) return; + const rect = el.getBoundingClientRect(); + // width < 576 或 height < 380 时隐藏 + setShowSkipButtons(!(rect.width < 576 || rect.height < 380)); + }; + + // 尝试立即更新一次 + updateShowSkipButtons(); + + const observer = new ResizeObserver(updateShowSkipButtons); + // 有可能此时 el 还未就绪,使用轮询确保绑定 + let retryTimer: NodeJS.Timeout | null = null; + const attachObserver = () => { + const el: HTMLElement | undefined = (playerRef.current as any)?.el; + if (el) { + observer.observe(el); + if (retryTimer) clearInterval(retryTimer); + } + }; + + attachObserver(); + if (!(playerRef.current as any)?.el) { + // 如果首次未获取到 el,继续重试直至获取 + retryTimer = setInterval(attachObserver, 200); + } + + // orientationchange 也可能影响高/宽 + window.addEventListener('orientationchange', updateShowSkipButtons); + + return () => { + observer.disconnect(); + if (retryTimer) clearInterval(retryTimer); + window.removeEventListener('orientationchange', updateShowSkipButtons); + }; + }, []); + // 换源相关状态 const [searchResults, setSearchResults] = useState([]); const [searchLoading, setSearchLoading] = useState(false); @@ -1339,31 +1389,33 @@ function PlayPageClient() { airPlayButton: null, // 隐藏默认 AirPlay 按钮 beforeCurrentTime: ( <> - {/* 快进 10 秒按钮 - 移动端隐藏 */} - + + {/* 双三角快进图标 */} + + + + + )} {totalEpisodes > 1 && ( // 下一集按钮放在时间显示前 @@ -1411,29 +1463,33 @@ function PlayPageClient() { ), - // 快退 10 秒按钮(移动端隐藏) + // 快退 10 秒按钮(根据播放器尺寸决定显隐) beforePlayButton: ( - + <> + {showSkipButtons && ( + + )} + ), }} />