@@ -78,6 +78,7 @@ export interface VideoRef {
78
78
play : ( ) => void ;
79
79
pause : ( ) => void ;
80
80
goToFrame : ( frame : number ) => void ;
81
+ frameSteppedTime : ( time ?: number ) => number ;
81
82
seek : ( time : number ) => void ;
82
83
setContrast : ( value : number ) => void ;
83
84
setBrightness : ( value : number ) => void ;
@@ -413,11 +414,23 @@ export const VideoCanvas = memo(
413
414
} ,
414
415
pause ( ) {
415
416
videoRef . current ?. pause ( ) ;
417
+ if ( isFF ( FF_VIDEO_FRAME_SEEK_PRECISION ) ) {
418
+ this . currentTime = clamp ( this . frameSteppedTime ( ) , 0 , this . duration ) ;
419
+ }
416
420
} ,
417
421
seek ( time ) {
418
422
this . currentTime = clamp ( time , 0 , this . duration ) ;
419
423
requestAnimationFrame ( ( ) => drawVideo ( ) ) ;
420
424
} ,
425
+ frameSteppedTime ( time ?: number ) : number {
426
+ if ( isFF ( FF_VIDEO_FRAME_SEEK_PRECISION ) ) {
427
+ return (
428
+ Math . round ( ( time ?? this . currentTime ) / BROWSER_TIME_PRECISION ) * BROWSER_TIME_PRECISION +
429
+ BROWSER_TIME_PRECISION
430
+ ) ;
431
+ }
432
+ return time ?? this . currentTime ;
433
+ } ,
421
434
goToFrame ( frame : number ) {
422
435
const frameClamped = clamp ( frame , 1 , length ) ;
423
436
@@ -429,8 +442,7 @@ export const VideoCanvas = memo(
429
442
const exactTime = frameZeroBased / framerate ;
430
443
431
444
// Round to next closest browser precision frame time
432
- this . currentTime =
433
- Math . round ( exactTime / BROWSER_TIME_PRECISION ) * BROWSER_TIME_PRECISION + BROWSER_TIME_PRECISION ;
445
+ this . currentTime = this . frameSteppedTime ( exactTime ) ;
434
446
} ,
435
447
} ;
436
448
0 commit comments