From c3fc20129a35e55efa1e447945520803fc9a8423 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Wed, 13 Mar 2024 21:21:42 -0500 Subject: [PATCH] use a single source of truth for scrubbing --- .../player/dynamic/DynamicVideoController.ts | 10 ++++------ .../components/player/dynamic/DynamicVideoPlayer.tsx | 5 +++-- web/src/views/events/RecordingView.tsx | 2 ++ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/web/src/components/player/dynamic/DynamicVideoController.ts b/web/src/components/player/dynamic/DynamicVideoController.ts index 45101c27f..26e8aaf20 100644 --- a/web/src/components/player/dynamic/DynamicVideoController.ts +++ b/web/src/components/player/dynamic/DynamicVideoController.ts @@ -9,7 +9,7 @@ export class DynamicVideoController { public camera = ""; private playerController: HTMLVideoElement; private previewController: PreviewController; - private setScrubbing: (isScrubbing: boolean) => void; + private isScrubbing: boolean; private setFocusedItem: (timeline: Timeline) => void; private playerMode: PlayerMode = "playback"; @@ -24,7 +24,7 @@ export class DynamicVideoController { previewController: PreviewController, annotationOffset: number, defaultMode: PlayerMode, - setScrubbing: (isScrubbing: boolean) => void, + isScrubbing: boolean, setFocusedItem: (timeline: Timeline) => void, ) { this.camera = camera; @@ -32,7 +32,7 @@ export class DynamicVideoController { this.previewController = previewController; this.annotationOffset = annotationOffset; this.playerMode = defaultMode; - this.setScrubbing = setScrubbing; + this.isScrubbing = isScrubbing; this.setFocusedItem = setFocusedItem; } @@ -52,7 +52,6 @@ export class DynamicVideoController { seekToTimestamp(time: number, play: boolean = false) { if (this.playerMode != "playback") { this.playerMode = "playback"; - this.setScrubbing(false); } if ( @@ -123,10 +122,9 @@ export class DynamicVideoController { this.previewController.setNewPreviewStartTime(time); } - if (scrubResult && this.playerMode != "scrubbing") { + if (scrubResult && this.playerMode != "scrubbing" && !this.isScrubbing) { this.playerMode = "scrubbing"; this.playerController.pause(); - this.setScrubbing(true); } } diff --git a/web/src/components/player/dynamic/DynamicVideoPlayer.tsx b/web/src/components/player/dynamic/DynamicVideoPlayer.tsx index 96fbc80fa..8550eafac 100644 --- a/web/src/components/player/dynamic/DynamicVideoPlayer.tsx +++ b/web/src/components/player/dynamic/DynamicVideoPlayer.tsx @@ -21,6 +21,7 @@ type DynamicVideoPlayerProps = { onControllerReady: (controller: DynamicVideoController) => void; onTimestampUpdate?: (timestamp: number) => void; onClipEnded?: () => void; + isScrubbing: boolean; }; export default function DynamicVideoPlayer({ className, @@ -31,6 +32,7 @@ export default function DynamicVideoPlayer({ onControllerReady, onTimestampUpdate, onClipEnded, + isScrubbing, }: DynamicVideoPlayerProps) { const apiHost = useApiHost(); const { data: config } = useSWR("config"); @@ -53,7 +55,6 @@ export default function DynamicVideoPlayer({ const playerRef = useRef(null); const [previewController, setPreviewController] = useState(null); - const [isScrubbing, setIsScrubbing] = useState(false); const [focusedItem, setFocusedItem] = useState( undefined, ); @@ -68,7 +69,7 @@ export default function DynamicVideoPlayer({ previewController, (config.cameras[camera]?.detect?.annotation_offset || 0) / 1000, "playback", - setIsScrubbing, + isScrubbing, setFocusedItem, ); // we only want to fire once when players are ready diff --git a/web/src/views/events/RecordingView.tsx b/web/src/views/events/RecordingView.tsx index 2bf96daaf..6235d812d 100644 --- a/web/src/views/events/RecordingView.tsx +++ b/web/src/views/events/RecordingView.tsx @@ -234,6 +234,7 @@ export function DesktopRecordingView({ onControllerReady={(controller) => { mainControllerRef.current = controller; }} + isScrubbing={scrubbing} />
@@ -452,6 +453,7 @@ export function MobileRecordingView({ }} onTimestampUpdate={setCurrentTime} onClipEnded={onClipEnded} + isScrubbing={scrubbing} />