feat: remove long press 3x playbackrate

This commit is contained in:
shinya
2025-06-27 13:38:43 +08:00
parent 7e401c2e23
commit 3eb176a802

View File

@@ -115,13 +115,6 @@ function PlayPageClient() {
);
const [isFullscreen, setIsFullscreen] = useState(false);
// 长按三倍速相关状态
const [isLongPressing, setIsLongPressing] = useState(false);
const [showSpeedTip, setShowSpeedTip] = useState(false);
const longPressTimeoutRef = useRef<NodeJS.Timeout | null>(null);
const originalPlaybackRateRef = useRef<number>(1);
const speedTipTimeoutRef = useRef<NodeJS.Timeout | null>(null);
// 用于记录是否需要在播放器 ready 后跳转到指定进度
const resumeTimeRef = useRef<number | null>(null);
@@ -403,12 +396,6 @@ function PlayPageClient() {
if (saveIntervalRef.current) {
clearInterval(saveIntervalRef.current);
}
if (longPressTimeoutRef.current) {
clearTimeout(longPressTimeoutRef.current);
}
if (speedTipTimeoutRef.current) {
clearTimeout(speedTipTimeoutRef.current);
}
};
}, []);
@@ -950,103 +937,6 @@ function PlayPageClient() {
};
}, []);
// 长按三倍速处理函数
const handleTouchStart = (e: TouchEvent) => {
// 防止在控制栏区域触发
const target = e.target as HTMLElement;
if (
target.closest('.vds-controls') ||
target.closest('.vds-context-menu') ||
target.closest('.vds-lazy-gesture')
) {
return;
}
// 仅在播放时触发
if (!playerRef.current?.playing) {
return;
}
// 清除之前的定时器
if (longPressTimeoutRef.current) {
clearTimeout(longPressTimeoutRef.current);
}
// 设置长按检测定时器500ms
longPressTimeoutRef.current = setTimeout(() => {
if (playerRef.current) {
// 保存原始播放速度
originalPlaybackRateRef.current = playerRef.current.playbackRate;
// 设置三倍速
playerRef.current.playbackRate = 3;
// 更新状态
setIsLongPressing(true);
setShowSpeedTip(true);
// 触发震动反馈(如果支持)
if (navigator.vibrate) {
navigator.vibrate(50);
}
// 3秒后自动隐藏提示
if (speedTipTimeoutRef.current) {
clearTimeout(speedTipTimeoutRef.current);
}
speedTipTimeoutRef.current = setTimeout(() => {
setShowSpeedTip(false);
}, 3000);
}
}, 500);
};
const handleTouchEnd = () => {
// 清除长按检测定时器
if (longPressTimeoutRef.current) {
clearTimeout(longPressTimeoutRef.current);
longPressTimeoutRef.current = null;
}
// 如果正在长按,恢复原始播放速度
if (isLongPressing && playerRef.current) {
playerRef.current.playbackRate = originalPlaybackRateRef.current;
setIsLongPressing(false);
setShowSpeedTip(false);
// 清除提示定时器
if (speedTipTimeoutRef.current) {
clearTimeout(speedTipTimeoutRef.current);
speedTipTimeoutRef.current = null;
}
}
};
// 添加触摸事件监听器
useEffect(() => {
const playerEl = playerRef.current?.el;
if (!playerEl) return;
const disableContextMenu = (e: Event) => {
e.preventDefault();
e.stopPropagation();
};
playerEl.addEventListener('touchstart', handleTouchStart, {
passive: true,
});
playerEl.addEventListener('touchend', handleTouchEnd, { passive: true });
playerEl.addEventListener('touchcancel', handleTouchEnd, { passive: true });
playerEl.addEventListener('contextmenu', disableContextMenu);
return () => {
playerEl.removeEventListener('touchstart', handleTouchStart);
playerEl.removeEventListener('touchend', handleTouchEnd);
playerEl.removeEventListener('touchcancel', handleTouchEnd);
playerEl.removeEventListener('contextmenu', disableContextMenu);
};
}, [playerRef.current, isLongPressing]);
/* -------------------- 设置 meta theme-color 为纯黑 -------------------- */
useEffect(() => {
const originalThemeColorTags = Array.from(
@@ -1797,30 +1687,6 @@ function PlayPageClient() {
<span className='text-white font-medium'>{shortcutText}</span>
</div>
</div>
{/* 三倍速提示 */}
<div
className={`absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 z-50 transition-opacity duration-300 ${
showSpeedTip ? 'opacity-100' : 'opacity-0 pointer-events-none'
}`}
>
<div className='bg-black/60 backdrop-blur-sm rounded-lg p-4 flex items-center space-x-3'>
<svg
className='w-6 h-6 text-white animate-pulse'
fill='none'
stroke='currentColor'
viewBox='0 0 24 24'
>
<path
strokeLinecap='round'
strokeLinejoin='round'
strokeWidth='2'
d='M13 10V3L4 14h7v7l9-11h-7z'
/>
</svg>
<span className='text-white font-bold text-lg'>3x </span>
</div>
</div>
</MediaPlayer>
</div>
);