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 preview getting wrong update time #10534

Merged
merged 5 commits into from
Mar 19, 2024
Merged
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
28 changes: 7 additions & 21 deletions web/src/components/player/PreviewPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,25 +272,12 @@ class PreviewVideoController extends PreviewController {
return false;
}

const seekTime = time - this.preview.start;

if (
isAndroid &&
isChrome &&
this.scrubbing &&
Math.abs(seekTime - this.previewRef.current.currentTime) > 400
) {
// android/chrome has incorrect timestamps sent that are before the expected seek time
return false;
}
const seekTime = Math.max(0, time - this.preview.start);

if (this.seeking) {
this.timeToSeek = time;
this.timeToSeek = seekTime;
} else {
this.previewRef.current.currentTime = Math.max(
0,
time - this.preview.start,
);
this.previewRef.current.currentTime = seekTime;
this.seeking = true;
}

Expand All @@ -303,16 +290,15 @@ class PreviewVideoController extends PreviewController {
}

if (this.timeToSeek) {
const diff =
Math.round(this.timeToSeek) -
Math.round(this.previewRef.current.currentTime + this.preview.start);
const diff = Math.round(
this.timeToSeek - this.previewRef.current.currentTime,
);

const scrubLimit = isMobile ? 1 : 0.5;

if (Math.abs(diff) >= scrubLimit) {
// only seek if there is an appropriate amount of time difference
this.previewRef.current.currentTime =
this.timeToSeek - this.preview.start;
this.previewRef.current.currentTime = this.timeToSeek;
} else {
this.seeking = false;
this.timeToSeek = undefined;
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/player/PreviewThumbnailPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type PreviewPlayerProps = {
review: ReviewSegment;
allPreviews?: Preview[];
scrollLock?: boolean;
onTimeUpdate?: React.Dispatch<React.SetStateAction<number | undefined>>;
onTimeUpdate?: (time: number | undefined) => void;
setReviewed: (review: ReviewSegment) => void;
onClick: (reviewId: string, ctrl: boolean) => void;
};
Expand Down
12 changes: 9 additions & 3 deletions web/src/components/player/dynamic/DynamicVideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ export default function DynamicVideoPlayer({

const onTimeUpdate = useCallback(
(time: number) => {
if (!controller || !onTimestampUpdate || time == 0) {
if (isScrubbing || !controller || !onTimestampUpdate || time == 0) {
return;
}

onTimestampUpdate(controller.getProgress(time));
},
[controller, onTimestampUpdate],
[controller, onTimestampUpdate, isScrubbing],
);

// state of playback player
Expand Down Expand Up @@ -176,7 +176,13 @@ export default function DynamicVideoPlayer({
onTimeUpdate={onTimeUpdate}
onPlayerLoaded={onPlayerLoaded}
onClipEnded={onClipEnded}
onPlaying={() => setIsLoading(false)}
onPlaying={() => {
if (isScrubbing) {
playerRef.current?.pause();
}

setIsLoading(false);
}}
>
{config && focusedItem && (
<TimelineEventOverlay
Expand Down
16 changes: 15 additions & 1 deletion web/src/views/events/EventView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,20 @@ function DetectionReview({

const [previewTime, setPreviewTime] = useState<number>();

const onPreviewTimeUpdate = useCallback(
(time: number | undefined) => {
if (!time) {
setPreviewTime(time);
return;
}

if (!previewTime || time > previewTime) {
setPreviewTime(time);
}
},
[previewTime, setPreviewTime],
);

// review interaction

const [hasUpdate, setHasUpdate] = useState(false);
Expand Down Expand Up @@ -483,7 +497,7 @@ function DetectionReview({
allPreviews={relevantPreviews}
setReviewed={markItemAsReviewed}
scrollLock={scrollLock}
onTimeUpdate={setPreviewTime}
onTimeUpdate={onPreviewTimeUpdate}
onClick={onSelectReview}
/>
</div>
Expand Down
Loading