From 95e4a733ee0384d69289ac815f28eea99b2b3d7d Mon Sep 17 00:00:00 2001 From: kuekhaoyang Date: Sun, 23 Nov 2025 21:59:00 +0800 Subject: [PATCH] fix: Prevent video from getting stuck at 00:00:00 by seeking to 0.1s on start and enable autoplay by default. --- components/player/VideoPlayer.tsx | 2 +- components/player/hooks/desktop/usePlaybackControls.ts | 9 ++++++--- .../player/hooks/mobile/useMobilePlaybackControls.ts | 9 ++++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/components/player/VideoPlayer.tsx b/components/player/VideoPlayer.tsx index 2533090..4e22d0d 100644 --- a/components/player/VideoPlayer.tsx +++ b/components/player/VideoPlayer.tsx @@ -18,7 +18,7 @@ interface VideoPlayerProps { export function VideoPlayer({ playUrl, videoId, currentEpisode, onBack }: VideoPlayerProps) { const [videoError, setVideoError] = useState(''); const [useProxy, setUseProxy] = useState(false); - const [shouldAutoPlay, setShouldAutoPlay] = useState(false); + const [shouldAutoPlay, setShouldAutoPlay] = useState(true); // Use reactive hook to subscribe to history updates // This ensures the component re-renders when history is hydrated from localStorage const viewingHistory = useHistoryStore(state => state.viewingHistory); diff --git a/components/player/hooks/desktop/usePlaybackControls.ts b/components/player/hooks/desktop/usePlaybackControls.ts index 82762fb..2f5e74d 100644 --- a/components/player/hooks/desktop/usePlaybackControls.ts +++ b/components/player/hooks/desktop/usePlaybackControls.ts @@ -60,9 +60,12 @@ export function usePlaybackControls({ if (!videoRef.current) return; setDuration(videoRef.current.duration); setIsLoading(false); - if (initialTime > 0) { - videoRef.current.currentTime = initialTime; - } + + // Fix for stuck at 00:00:00: + // If initialTime is 0, we seek to a tiny offset to help the browser/HLS buffer start. + const startPosition = initialTime > 0 ? initialTime : 0.1; + videoRef.current.currentTime = startPosition; + videoRef.current.play().catch((err: Error) => { console.warn('Autoplay was prevented:', err); }); diff --git a/components/player/hooks/mobile/useMobilePlaybackControls.ts b/components/player/hooks/mobile/useMobilePlaybackControls.ts index 49e8fcd..6e2c201 100644 --- a/components/player/hooks/mobile/useMobilePlaybackControls.ts +++ b/components/player/hooks/mobile/useMobilePlaybackControls.ts @@ -75,9 +75,12 @@ export function useMobilePlaybackControls({ if (!videoRef.current) return; setDuration(videoRef.current.duration); setIsLoading(false); - if (initialTime > 0) { - videoRef.current.currentTime = initialTime; - } + + // Fix for stuck at 00:00:00: + // If initialTime is 0, we seek to a tiny offset to help the browser/HLS buffer start. + const startPosition = initialTime > 0 ? initialTime : 0.1; + videoRef.current.currentTime = startPosition; + videoRef.current.play().catch((err: Error) => { console.warn('Autoplay was prevented:', err); });