@@ -78,6 +78,7 @@ export interface VideoRef {
7878 play : ( ) => void ;
7979 pause : ( ) => void ;
8080 goToFrame : ( frame : number ) => void ;
81+ frameSteppedTime : ( time ?: number ) => number ;
8182 seek : ( time : number ) => void ;
8283 setContrast : ( value : number ) => void ;
8384 setBrightness : ( value : number ) => void ;
@@ -413,11 +414,23 @@ export const VideoCanvas = memo(
413414 } ,
414415 pause ( ) {
415416 videoRef . current ?. pause ( ) ;
417+ if ( isFF ( FF_VIDEO_FRAME_SEEK_PRECISION ) ) {
418+ this . currentTime = clamp ( this . frameSteppedTime ( ) , 0 , this . duration ) ;
419+ }
416420 } ,
417421 seek ( time ) {
418422 this . currentTime = clamp ( time , 0 , this . duration ) ;
419423 requestAnimationFrame ( ( ) => drawVideo ( ) ) ;
420424 } ,
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+ } ,
421434 goToFrame ( frame : number ) {
422435 const frameClamped = clamp ( frame , 1 , length ) ;
423436
@@ -429,8 +442,7 @@ export const VideoCanvas = memo(
429442 const exactTime = frameZeroBased / framerate ;
430443
431444 // 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 ) ;
434446 } ,
435447 } ;
436448
0 commit comments