From 8c0275fe2f5c11afd1f8d38afbabdecd58903a23 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Tue, 12 Mar 2024 09:24:18 -0600 Subject: [PATCH] Add special casing for android preview scrubbing (#10398) * Add special casing for android scrubbing * Fix motion data --- web/src/components/player/PreviewPlayer.tsx | 40 +++++++++++++-------- web/src/views/events/RecordingView.tsx | 4 +-- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/web/src/components/player/PreviewPlayer.tsx b/web/src/components/player/PreviewPlayer.tsx index bf61698b5..fd9248697 100644 --- a/web/src/components/player/PreviewPlayer.tsx +++ b/web/src/components/player/PreviewPlayer.tsx @@ -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,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; @@ -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; } diff --git a/web/src/views/events/RecordingView.tsx b/web/src/views/events/RecordingView.tsx index bf9688ae4..f95d99ec6 100644 --- a/web/src/views/events/RecordingView.tsx +++ b/web/src/views/events/RecordingView.tsx @@ -134,7 +134,7 @@ export function DesktopRecordingView({ const { data: motionData } = useSWR( severity == "significant_motion" ? [ - "review/activity", + "review/activity/motion", { before: timeRange.end, after: timeRange.start, @@ -351,7 +351,7 @@ export function MobileRecordingView({ const { data: motionData } = useSWR( severity == "significant_motion" ? [ - "review/activity", + "review/activity/motion", { before: timeRange.end, after: timeRange.start,