Fix preview getting wrong update time (#10534)

* Fix preview getting wrong update time

* remove dead logic

* Cleanup

* Fix case where multiple previews play at the same time

* Fix typing
This commit is contained in:
Nicolas Mowen 2024-03-19 07:34:49 -06:00 committed by GitHub
parent 5c3925ab50
commit ccdf9a2f0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 32 additions and 26 deletions

View File

@ -272,25 +272,12 @@ class PreviewVideoController extends PreviewController {
return false; return false;
} }
const seekTime = time - this.preview.start; const seekTime = Math.max(0, 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;
}
if (this.seeking) { if (this.seeking) {
this.timeToSeek = time; this.timeToSeek = seekTime;
} else { } else {
this.previewRef.current.currentTime = Math.max( this.previewRef.current.currentTime = seekTime;
0,
time - this.preview.start,
);
this.seeking = true; this.seeking = true;
} }
@ -303,16 +290,15 @@ class PreviewVideoController extends PreviewController {
} }
if (this.timeToSeek) { if (this.timeToSeek) {
const diff = const diff = Math.round(
Math.round(this.timeToSeek) - this.timeToSeek - this.previewRef.current.currentTime,
Math.round(this.previewRef.current.currentTime + this.preview.start); );
const scrubLimit = isMobile ? 1 : 0.5; const scrubLimit = isMobile ? 1 : 0.5;
if (Math.abs(diff) >= scrubLimit) { if (Math.abs(diff) >= scrubLimit) {
// only seek if there is an appropriate amount of time difference // only seek if there is an appropriate amount of time difference
this.previewRef.current.currentTime = this.previewRef.current.currentTime = this.timeToSeek;
this.timeToSeek - this.preview.start;
} else { } else {
this.seeking = false; this.seeking = false;
this.timeToSeek = undefined; this.timeToSeek = undefined;

View File

@ -24,7 +24,7 @@ type PreviewPlayerProps = {
review: ReviewSegment; review: ReviewSegment;
allPreviews?: Preview[]; allPreviews?: Preview[];
scrollLock?: boolean; scrollLock?: boolean;
onTimeUpdate?: React.Dispatch<React.SetStateAction<number | undefined>>; onTimeUpdate?: (time: number | undefined) => void;
setReviewed: (review: ReviewSegment) => void; setReviewed: (review: ReviewSegment) => void;
onClick: (reviewId: string, ctrl: boolean) => void; onClick: (reviewId: string, ctrl: boolean) => void;
}; };

View File

@ -120,13 +120,13 @@ export default function DynamicVideoPlayer({
const onTimeUpdate = useCallback( const onTimeUpdate = useCallback(
(time: number) => { (time: number) => {
if (!controller || !onTimestampUpdate || time == 0) { if (isScrubbing || !controller || !onTimestampUpdate || time == 0) {
return; return;
} }
onTimestampUpdate(controller.getProgress(time)); onTimestampUpdate(controller.getProgress(time));
}, },
[controller, onTimestampUpdate], [controller, onTimestampUpdate, isScrubbing],
); );
// state of playback player // state of playback player
@ -176,7 +176,13 @@ export default function DynamicVideoPlayer({
onTimeUpdate={onTimeUpdate} onTimeUpdate={onTimeUpdate}
onPlayerLoaded={onPlayerLoaded} onPlayerLoaded={onPlayerLoaded}
onClipEnded={onClipEnded} onClipEnded={onClipEnded}
onPlaying={() => setIsLoading(false)} onPlaying={() => {
if (isScrubbing) {
playerRef.current?.pause();
}
setIsLoading(false);
}}
> >
{config && focusedItem && ( {config && focusedItem && (
<TimelineEventOverlay <TimelineEventOverlay

View File

@ -349,6 +349,20 @@ function DetectionReview({
const [previewTime, setPreviewTime] = useState<number>(); 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 // review interaction
const [hasUpdate, setHasUpdate] = useState(false); const [hasUpdate, setHasUpdate] = useState(false);
@ -483,7 +497,7 @@ function DetectionReview({
allPreviews={relevantPreviews} allPreviews={relevantPreviews}
setReviewed={markItemAsReviewed} setReviewed={markItemAsReviewed}
scrollLock={scrollLock} scrollLock={scrollLock}
onTimeUpdate={setPreviewTime} onTimeUpdate={onPreviewTimeUpdate}
onClick={onSelectReview} onClick={onSelectReview}
/> />
</div> </div>