mirror of
https://github.com/KuekHaoYang/KVideo.git
synced 2026-08-15 08:43:44 +08:00
fix: Refine video seeking logic in playback controls to prevent overwrites and offset HLS preloader start index to avoid browser competition.
This commit is contained in:
@@ -64,9 +64,12 @@ export function usePlaybackControls({
|
||||
setIsLoading(false);
|
||||
|
||||
// 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;
|
||||
// Only seek if we are at the very start (to avoid overwriting a previous seek)
|
||||
if (videoRef.current.currentTime < 0.5) {
|
||||
// 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);
|
||||
|
||||
@@ -79,9 +79,12 @@ export function useMobilePlaybackControls({
|
||||
setIsLoading(false);
|
||||
|
||||
// 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;
|
||||
// Only seek if we are at the very start (to avoid overwriting a previous seek)
|
||||
if (videoRef.current.currentTime < 0.5) {
|
||||
// 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);
|
||||
|
||||
@@ -61,6 +61,10 @@ export function useHLSPreloader({ src, currentTime }: UseHLSPreloaderProps) {
|
||||
}
|
||||
}
|
||||
|
||||
// Offset start index by 3 segments to avoid competing with browser playback
|
||||
// The browser needs the immediate segments NOW; we preload the future.
|
||||
startIndex = Math.min(startIndex + 3, segmentsRef.current.length - 1);
|
||||
|
||||
if (startIndex >= segmentsRef.current.length) return;
|
||||
|
||||
// Check if this is sequential playback or a seek
|
||||
|
||||
Reference in New Issue
Block a user