Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: OPTIC-1677: Incorrect video frame rendered when pausing a video during playback #7078

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions web/libs/editor/src/components/VideoCanvas/VideoCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export interface VideoRef {
play: () => void;
pause: () => void;
goToFrame: (frame: number) => void;
frameSteppedTime: (time?: number) => number;
seek: (time: number) => void;
setContrast: (value: number) => void;
setBrightness: (value: number) => void;
Expand Down Expand Up @@ -413,11 +414,23 @@ export const VideoCanvas = memo(
},
pause() {
videoRef.current?.pause();
if (isFF(FF_VIDEO_FRAME_SEEK_PRECISION)) {
this.currentTime = clamp(this.frameSteppedTime(), 0, this.duration);
}
},
seek(time) {
this.currentTime = clamp(time, 0, this.duration);
requestAnimationFrame(() => drawVideo());
},
frameSteppedTime(time?: number): number {
if (isFF(FF_VIDEO_FRAME_SEEK_PRECISION)) {
return (
Math.round((time ?? this.currentTime) / BROWSER_TIME_PRECISION) * BROWSER_TIME_PRECISION +
BROWSER_TIME_PRECISION
);
}
return time ?? this.currentTime;
},
goToFrame(frame: number) {
const frameClamped = clamp(frame, 1, length);

Expand All @@ -429,8 +442,7 @@ export const VideoCanvas = memo(
const exactTime = frameZeroBased / framerate;

// Round to next closest browser precision frame time
this.currentTime =
Math.round(exactTime / BROWSER_TIME_PRECISION) * BROWSER_TIME_PRECISION + BROWSER_TIME_PRECISION;
this.currentTime = this.frameSteppedTime(exactTime);
},
};

Expand Down
2 changes: 1 addition & 1 deletion web/libs/editor/src/tags/object/Video/Video.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const Model = types
self.syncSend(
{
playing: self.ref.current.playing,
time: self.ref.current.currentTime,
time: self.ref.current.frameSteppedTime(),
...data,
},
event,
Expand Down
Loading