Skip to content

Commit 6691ef0

Browse files
bmartelMihajloHoma
andauthored
fix: OPTIC-1677: Incorrect video frame rendered when pausing a video during playback (#7078)
Co-authored-by: bmartel <[email protected]> Co-authored-by: MihajloHoma <[email protected]>
1 parent 8c6f3ad commit 6691ef0

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

web/libs/editor/src/components/VideoCanvas/VideoCanvas.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

web/libs/editor/src/tags/object/Video/Video.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ const Model = types
128128
self.syncSend(
129129
{
130130
playing: self.ref.current.playing,
131-
time: self.ref.current.currentTime,
131+
time: self.ref.current.frameSteppedTime(),
132132
...data,
133133
},
134134
event,

0 commit comments

Comments
 (0)