Add special casing for android scrubbing

This commit is contained in:
Nicolas Mowen 2024-03-12 06:02:35 -06:00
parent 579a7c8900
commit 6940adb7a2

View File

@ -12,6 +12,7 @@ import { Preview } from "@/types/preview";
import { PreviewPlayback } from "@/types/playback";
import { isCurrentHour } from "@/utils/dateUtil";
import { baseUrl } from "@/api/baseUrl";
import { isAndroid } from "react-device-detect";
type PreviewPlayerProps = {
className?: string;
@ -235,7 +236,7 @@ class PreviewVideoController extends PreviewController {
}
override scrubToTimestamp(time: number): boolean {
if (!this.preview || !this.timeRange) {
if (!this.previewRef.current || !this.preview || !this.timeRange) {
return false;
}
@ -246,14 +247,12 @@ class PreviewVideoController extends PreviewController {
if (this.seeking) {
this.timeToSeek = time;
} else {
if (this.previewRef.current) {
this.previewRef.current.currentTime = Math.max(
0,
time - this.preview.start,
);
this.seeking = true;
}
}
return true;
}
@ -263,12 +262,25 @@ class PreviewVideoController extends PreviewController {
return;
}
if (this.timeToSeek) {
if (
this.timeToSeek &&
this.timeToSeek != this.previewRef.current?.currentTime
Math.round(this.previewRef.current.currentTime + this.preview.start) !=
Math.round(this.timeToSeek)
) {
if (isAndroid) {
const currentTs =
this.previewRef.current.currentTime + this.preview.start;
this.previewRef.current.currentTime =
this.previewRef.current.currentTime +
(this.timeToSeek - currentTs) / 2;
} else {
this.previewRef.current.currentTime =
this.timeToSeek - this.preview.start;
}
} else {
this.seeking = false;
this.timeToSeek = undefined;
}
} else {
this.seeking = false;
}