mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-10 05:05:26 +03:00
Allow playback on motion screen
This commit is contained in:
parent
ed5cf4df87
commit
8b89a54e50
@ -10,7 +10,7 @@ import Hls from "hls.js";
|
|||||||
import { isDesktop, isMobile } from "react-device-detect";
|
import { isDesktop, isMobile } from "react-device-detect";
|
||||||
import useKeyboardListener from "@/hooks/use-keyboard-listener";
|
import useKeyboardListener from "@/hooks/use-keyboard-listener";
|
||||||
import { TransformComponent, TransformWrapper } from "react-zoom-pan-pinch";
|
import { TransformComponent, TransformWrapper } from "react-zoom-pan-pinch";
|
||||||
import VideoControls from "./PlayerControls";
|
import VideoControls from "./VideoControls";
|
||||||
|
|
||||||
const HLS_MIME_TYPE = "application/vnd.apple.mpegurl" as const;
|
const HLS_MIME_TYPE = "application/vnd.apple.mpegurl" as const;
|
||||||
const unsupportedErrorCodes = [
|
const unsupportedErrorCodes = [
|
||||||
@ -210,6 +210,26 @@ export default function HlsVideoPlayer({
|
|||||||
show={controls}
|
show={controls}
|
||||||
controlsOpen={controlsOpen}
|
controlsOpen={controlsOpen}
|
||||||
setControlsOpen={setControlsOpen}
|
setControlsOpen={setControlsOpen}
|
||||||
|
onPlayPause={(play) => {
|
||||||
|
if (!videoRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (play) {
|
||||||
|
videoRef.current.play();
|
||||||
|
} else {
|
||||||
|
videoRef.current.pause();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onSeek={(diff) => {
|
||||||
|
const currentTime = videoRef.current?.currentTime;
|
||||||
|
|
||||||
|
if (!videoRef.current || !currentTime) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
videoRef.current.currentTime = Math.max(0, currentTime + diff);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -32,12 +32,14 @@ const CONTROLS_DEFAULT: VideoControls = {
|
|||||||
|
|
||||||
type VideoControlsProps = {
|
type VideoControlsProps = {
|
||||||
className?: string;
|
className?: string;
|
||||||
video: HTMLVideoElement | null;
|
video?: HTMLVideoElement | null;
|
||||||
features?: VideoControls;
|
features?: VideoControls;
|
||||||
isPlaying: boolean;
|
isPlaying: boolean;
|
||||||
show: boolean;
|
show: boolean;
|
||||||
controlsOpen: boolean;
|
controlsOpen?: boolean;
|
||||||
setControlsOpen: (open: boolean) => void;
|
setControlsOpen?: (open: boolean) => void;
|
||||||
|
onPlayPause: (play: boolean) => void;
|
||||||
|
onSeek: (diff: number) => void;
|
||||||
};
|
};
|
||||||
export default function VideoControls({
|
export default function VideoControls({
|
||||||
className,
|
className,
|
||||||
@ -47,6 +49,8 @@ export default function VideoControls({
|
|||||||
show,
|
show,
|
||||||
controlsOpen,
|
controlsOpen,
|
||||||
setControlsOpen,
|
setControlsOpen,
|
||||||
|
onPlayPause,
|
||||||
|
onSeek,
|
||||||
}: VideoControlsProps) {
|
}: VideoControlsProps) {
|
||||||
const playbackRates = useMemo(() => {
|
const playbackRates = useMemo(() => {
|
||||||
if (isSafari) {
|
if (isSafari) {
|
||||||
@ -59,48 +63,25 @@ export default function VideoControls({
|
|||||||
const onReplay = useCallback(
|
const onReplay = useCallback(
|
||||||
(e: React.MouseEvent<SVGElement>) => {
|
(e: React.MouseEvent<SVGElement>) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
onSeek(-10);
|
||||||
const currentTime = video?.currentTime;
|
|
||||||
|
|
||||||
if (!video || !currentTime) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
video.currentTime = Math.max(0, currentTime - 10);
|
|
||||||
},
|
},
|
||||||
[video],
|
[onSeek],
|
||||||
);
|
);
|
||||||
|
|
||||||
const onSkip = useCallback(
|
const onSkip = useCallback(
|
||||||
(e: React.MouseEvent<SVGElement>) => {
|
(e: React.MouseEvent<SVGElement>) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
onSeek(10);
|
||||||
const currentTime = video?.currentTime;
|
|
||||||
|
|
||||||
if (!video || !currentTime) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
video.currentTime = currentTime + 10;
|
|
||||||
},
|
},
|
||||||
[video],
|
[onSeek],
|
||||||
);
|
);
|
||||||
|
|
||||||
const onTogglePlay = useCallback(
|
const onTogglePlay = useCallback(
|
||||||
(e: React.MouseEvent<HTMLDivElement>) => {
|
(e: React.MouseEvent<HTMLDivElement>) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
onPlayPause(!isPlaying);
|
||||||
if (!video) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isPlaying) {
|
|
||||||
video.pause();
|
|
||||||
} else {
|
|
||||||
video.play();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
[isPlaying, video],
|
[isPlaying, onPlayPause],
|
||||||
);
|
);
|
||||||
|
|
||||||
// volume control
|
// volume control
|
||||||
@ -119,7 +100,7 @@ export default function VideoControls({
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [video?.volume, video?.muted]);
|
}, [video?.volume, video?.muted]);
|
||||||
|
|
||||||
if (!video || !show) {
|
if (!show) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +108,7 @@ export default function VideoControls({
|
|||||||
<div
|
<div
|
||||||
className={`px-4 py-2 flex justify-between items-center gap-8 text-white z-50 bg-black bg-opacity-60 rounded-lg ${className ?? ""}`}
|
className={`px-4 py-2 flex justify-between items-center gap-8 text-white z-50 bg-black bg-opacity-60 rounded-lg ${className ?? ""}`}
|
||||||
>
|
>
|
||||||
{features.volume && (
|
{video && features.volume && (
|
||||||
<div className="flex justify-normal items-center gap-2">
|
<div className="flex justify-normal items-center gap-2">
|
||||||
<VolumeIcon
|
<VolumeIcon
|
||||||
className="size-5"
|
className="size-5"
|
||||||
@ -161,17 +142,19 @@ export default function VideoControls({
|
|||||||
{features.seek && (
|
{features.seek && (
|
||||||
<MdForward10 className="size-5 cursor-pointer" onClick={onSkip} />
|
<MdForward10 className="size-5 cursor-pointer" onClick={onSkip} />
|
||||||
)}
|
)}
|
||||||
{features.playbackRate && (
|
{video && features.playbackRate && (
|
||||||
<DropdownMenu
|
<DropdownMenu
|
||||||
open={controlsOpen}
|
open={controlsOpen == true}
|
||||||
onOpenChange={(open) => {
|
onOpenChange={(open) => {
|
||||||
setControlsOpen(open);
|
if (setControlsOpen) {
|
||||||
|
setControlsOpen(open);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<DropdownMenuTrigger>{`${video.playbackRate}x`}</DropdownMenuTrigger>
|
<DropdownMenuTrigger>{`${video.playbackRate}x`}</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent>
|
<DropdownMenuContent>
|
||||||
<DropdownMenuRadioGroup
|
<DropdownMenuRadioGroup
|
||||||
onValueChange={(rate) => (video.playbackRate = parseInt(rate))}
|
onValueChange={(rate) => (video.playbackRate = parseFloat(rate))}
|
||||||
>
|
>
|
||||||
{playbackRates.map((rate) => (
|
{playbackRates.map((rate) => (
|
||||||
<DropdownMenuRadioItem key={rate} value={rate.toString()}>
|
<DropdownMenuRadioItem key={rate} value={rate.toString()}>
|
||||||
@ -38,6 +38,7 @@ import PreviewPlayer, {
|
|||||||
} from "@/components/player/PreviewPlayer";
|
} from "@/components/player/PreviewPlayer";
|
||||||
import SummaryTimeline from "@/components/timeline/SummaryTimeline";
|
import SummaryTimeline from "@/components/timeline/SummaryTimeline";
|
||||||
import { RecordingStartingPoint } from "@/types/record";
|
import { RecordingStartingPoint } from "@/types/record";
|
||||||
|
import VideoControls from "@/components/player/VideoControls";
|
||||||
|
|
||||||
type EventViewProps = {
|
type EventViewProps = {
|
||||||
reviews?: ReviewSegment[];
|
reviews?: ReviewSegment[];
|
||||||
@ -678,6 +679,7 @@ function MotionReview({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const [scrubbing, setScrubbing] = useState(false);
|
const [scrubbing, setScrubbing] = useState(false);
|
||||||
|
const [playing, setPlaying] = useState(false);
|
||||||
|
|
||||||
// move to next clip
|
// move to next clip
|
||||||
|
|
||||||
@ -704,6 +706,33 @@ function MotionReview({
|
|||||||
});
|
});
|
||||||
}, [currentTime, currentTimeRange, timeRangeSegments]);
|
}, [currentTime, currentTimeRange, timeRangeSegments]);
|
||||||
|
|
||||||
|
// playback
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!playing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const startTime = currentTime;
|
||||||
|
let counter = 0;
|
||||||
|
const intervalId = setInterval(() => {
|
||||||
|
counter += 0.5;
|
||||||
|
|
||||||
|
if (startTime + counter >= timeRange.before) {
|
||||||
|
setPlaying(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setCurrentTime(startTime + counter);
|
||||||
|
}, 60);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
clearInterval(intervalId);
|
||||||
|
};
|
||||||
|
// do not render when current time changes
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [playing]);
|
||||||
|
|
||||||
if (!relevantPreviews) {
|
if (!relevantPreviews) {
|
||||||
return <ActivityIndicator />;
|
return <ActivityIndicator />;
|
||||||
}
|
}
|
||||||
@ -762,9 +791,30 @@ function MotionReview({
|
|||||||
motion_events={motionData ?? []}
|
motion_events={motionData ?? []}
|
||||||
severityType="significant_motion"
|
severityType="significant_motion"
|
||||||
contentRef={contentRef}
|
contentRef={contentRef}
|
||||||
onHandlebarDraggingChange={(scrubbing) => setScrubbing(scrubbing)}
|
onHandlebarDraggingChange={(scrubbing) => {
|
||||||
|
if (playing && scrubbing) {
|
||||||
|
setPlaying(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
setScrubbing(scrubbing);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<VideoControls
|
||||||
|
className="absolute bottom-16 left-1/2 -translate-x-1/2 bg-secondary"
|
||||||
|
features={{
|
||||||
|
volume: false,
|
||||||
|
seek: true,
|
||||||
|
playbackRate: false,
|
||||||
|
}}
|
||||||
|
isPlaying={playing}
|
||||||
|
onPlayPause={setPlaying}
|
||||||
|
onSeek={(diff) => {
|
||||||
|
setCurrentTime(currentTime + diff);
|
||||||
|
}}
|
||||||
|
show={currentTime < timeRange.before - 4}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user