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

Add special casing for android preview scrubbing #10398

Merged
merged 2 commits into from
Mar 12, 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
40 changes: 26 additions & 14 deletions web/src/components/player/PreviewPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -246,13 +247,11 @@ 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;
}
this.previewRef.current.currentTime = Math.max(
0,
time - this.preview.start,
);
this.seeking = true;
}

return true;
Expand All @@ -263,12 +262,25 @@ class PreviewVideoController extends PreviewController {
return;
}

if (
this.timeToSeek &&
this.timeToSeek != this.previewRef.current?.currentTime
) {
this.previewRef.current.currentTime =
this.timeToSeek - this.preview.start;
if (this.timeToSeek) {
if (
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;
}
Expand Down
4 changes: 2 additions & 2 deletions web/src/views/events/RecordingView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function DesktopRecordingView({
const { data: motionData } = useSWR<MotionData[]>(
severity == "significant_motion"
? [
"review/activity",
"review/activity/motion",
{
before: timeRange.end,
after: timeRange.start,
Expand Down Expand Up @@ -351,7 +351,7 @@ export function MobileRecordingView({
const { data: motionData } = useSWR<MotionData[]>(
severity == "significant_motion"
? [
"review/activity",
"review/activity/motion",
{
before: timeRange.end,
after: timeRange.start,
Expand Down
Loading