add video loading indicator

This commit is contained in:
Josh Hawkins 2024-09-11 12:17:53 -05:00
parent 4cbd02d0ef
commit 0cd12d2c38

View File

@ -32,6 +32,7 @@ import { Event } from "@/types/event";
import HlsVideoPlayer from "@/components/player/HlsVideoPlayer"; import HlsVideoPlayer from "@/components/player/HlsVideoPlayer";
import { baseUrl } from "@/api/baseUrl"; import { baseUrl } from "@/api/baseUrl";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import ActivityIndicator from "@/components/indicators/activity-indicator";
const SEARCH_TABS = ["details", "Frigate+", "video"] as const; const SEARCH_TABS = ["details", "Frigate+", "video"] as const;
type SearchTab = (typeof SEARCH_TABS)[number]; type SearchTab = (typeof SEARCH_TABS)[number];
@ -312,19 +313,26 @@ type VideoTabProps = {
search: SearchResult; search: SearchResult;
}; };
function VideoTab({ search }: VideoTabProps) { function VideoTab({ search }: VideoTabProps) {
const [isLoading, setIsLoading] = useState(true);
const videoRef = useRef<HTMLVideoElement | null>(null); const videoRef = useRef<HTMLVideoElement | null>(null);
const endTime = useMemo(() => search.end_time ?? Date.now() / 1000, [search]); const endTime = useMemo(() => search.end_time ?? Date.now() / 1000, [search]);
return ( return (
<HlsVideoPlayer <>
videoRef={videoRef} {isLoading && (
currentSource={`${baseUrl}vod/${search.camera}/start/${search.start_time}/end/${endTime}/index.m3u8`} <ActivityIndicator className="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2" />
hotKeys )}
visible <HlsVideoPlayer
frigateControls={false} videoRef={videoRef}
fullscreen={false} currentSource={`${baseUrl}vod/${search.camera}/start/${search.start_time}/end/${endTime}/index.m3u8`}
supportsFullscreen={false} hotKeys
/> visible
frigateControls={false}
fullscreen={false}
supportsFullscreen={false}
onPlaying={() => setIsLoading(false)}
/>
</>
); );
} }