mirror of
https://github.com/KuekHaoYang/KVideo.git
synced 2026-08-15 00:33:44 +08:00
fix: Prevent video from getting stuck at 00:00:00 by seeking to 0.1s on start and enable autoplay by default.
This commit is contained in:
@@ -18,7 +18,7 @@ interface VideoPlayerProps {
|
||||
export function VideoPlayer({ playUrl, videoId, currentEpisode, onBack }: VideoPlayerProps) {
|
||||
const [videoError, setVideoError] = useState<string>('');
|
||||
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);
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user