From 881b54b3de8d5c7d3faf3efbfc0f9f8d8f81fc3c Mon Sep 17 00:00:00 2001 From: shinya Date: Thu, 3 Jul 2025 20:13:52 +0800 Subject: [PATCH] feat: long press 3x playbackrate --- src/app/play/page.tsx | 53 ++++++++++++++++++++++++++++++++++++++++--- src/lib/runtime.ts | 4 ---- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/app/play/page.tsx b/src/app/play/page.tsx index 683ae32..5e71fb3 100644 --- a/src/app/play/page.tsx +++ b/src/app/play/page.tsx @@ -190,6 +190,10 @@ function PlayPageClient() { return true; }); + // 长按三倍速相关 + const longPressTimeoutRef = useRef(null); + const normalPlaybackRateRef = useRef(1); + // 同步最新值到 refs useEffect(() => { currentSourceRef.current = currentSource; @@ -393,6 +397,10 @@ function PlayPageClient() { } }, 0); } + + // 绑定长按三倍速事件 + playerRef.current?.addEventListener('touchstart', handleLongPressStart); + playerRef.current?.addEventListener('touchend', handleLongPressEnd); }; const onEnded = () => { @@ -452,6 +460,9 @@ function PlayPageClient() { if (saveIntervalRef.current) { clearInterval(saveIntervalRef.current); } + if (longPressTimeoutRef.current) { + clearTimeout(longPressTimeoutRef.current); + } }; }, []); @@ -1031,6 +1042,41 @@ function PlayPageClient() { } }; + // 长按三倍速处理 + const handleLongPressStart = (e: TouchEvent) => { + if (playerRef.current?.paused || playerRef.current?.playbackRate === 3.0) { + return; + } + const target = e.target as HTMLElement; + if ( + target.closest('.custom_topbar') || + target.closest('.custom_episodes_panel') || + target.closest('.custom_source_panel') + ) { + return; + } + if (longPressTimeoutRef.current) { + clearTimeout(longPressTimeoutRef.current); + } + longPressTimeoutRef.current = setTimeout(() => { + if (playerRef.current) { + normalPlaybackRateRef.current = playerRef.current.playbackRate || 1; + playerRef.current.playbackRate = 3.0; + displayShortcutHint('3倍速', 'play'); + } + }, 300); // 按压 300ms 触发 + }; + + const handleLongPressEnd = () => { + if (longPressTimeoutRef.current) { + clearTimeout(longPressTimeoutRef.current); + longPressTimeoutRef.current = null; + } + if (playerRef.current) { + playerRef.current.playbackRate = normalPlaybackRateRef.current || 1; + } + }; + if (loading) { return (
@@ -1114,7 +1160,7 @@ function PlayPageClient() { return (
{/* 返回按钮 */} @@ -1387,6 +1433,7 @@ function PlayPageClient() { /> @@ -1576,7 +1623,7 @@ function PlayPageClient() { {/* 侧拉面板 */}
diff --git a/src/lib/runtime.ts b/src/lib/runtime.ts index 4dff8ed..b18368e 100644 --- a/src/lib/runtime.ts +++ b/src/lib/runtime.ts @@ -43,10 +43,6 @@ export const config = { api: 'https://wolongzyw.com/api.php/provide/vod', name: '卧龙资源', }, - hwba: { - api: 'https://cjhwba.com/api.php/provide/vod', - name: '华为吧资源', - }, jisu: { api: 'https://jszyapi.com/api.php/provide/vod', name: '极速资源',