Fix preview getting wrong update time

This commit is contained in:
Nicolas Mowen 2024-03-19 06:49:19 -06:00
parent 5c3925ab50
commit d1b1d1182f
2 changed files with 15 additions and 14 deletions

View File

@ -281,16 +281,12 @@ class PreviewVideoController extends PreviewController {
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) {
this.timeToSeek = time;
this.timeToSeek = seekTime;
} else {
this.previewRef.current.currentTime = Math.max(
0,
time - this.preview.start,
);
this.previewRef.current.currentTime = Math.max(0, seekTime);
this.seeking = true;
}
@ -303,16 +299,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;

View File

@ -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
@ -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