fix: prevent unnecessary video seeking if current time is close to initial playback time.

This commit is contained in:
kuekhaoyang
2025-11-23 17:21:12 +08:00
parent 6dc6757ad1
commit 045247041d
2 changed files with 6 additions and 4 deletions
@@ -72,8 +72,9 @@ export function usePlaybackControls({
useEffect(() => {
if (initialTime > 0 && videoRef.current) {
// Only seek if we haven't progressed far (e.g. still near start)
// This prevents jumping if the user has already started watching
if (videoRef.current.currentTime < 2) {
// AND if the target time is significantly different from current time (> 0.5s)
// This prevents jumping if the user has already started watching and initialTime updates
if (videoRef.current.currentTime < 2 && Math.abs(videoRef.current.currentTime - initialTime) > 0.5) {
videoRef.current.currentTime = initialTime;
}
}
@@ -87,8 +87,9 @@ export function useMobilePlaybackControls({
useEffect(() => {
if (initialTime > 0 && videoRef.current) {
// Only seek if we haven't progressed far (e.g. still near start)
// This prevents jumping if the user has already started watching
if (videoRef.current.currentTime < 2) {
// AND if the target time is significantly different from current time (> 0.5s)
// This prevents jumping if the user has already started watching and initialTime updates
if (videoRef.current.currentTime < 2 && Math.abs(videoRef.current.currentTime - initialTime) > 0.5) {
videoRef.current.currentTime = initialTime;
}
}