import { useState } from "react"; import { cn } from "../../../lib/utils"; import { DEFAULT_PREVIEW_MAX_SECONDS, formatPreviewLength, } from "../../../lib/videoPreview"; type Props = { src: string; maxSeconds?: number; }; /** * Stops direct file playback after the first N seconds (admin short preview). */ export function PreviewLimitedFileVideo({ src, maxSeconds = DEFAULT_PREVIEW_MAX_SECONDS, }: Props) { const [capped, setCapped] = useState(false); const previewLengthLabel = formatPreviewLength(maxSeconds); const onTimeUpdate = (e: React.SyntheticEvent) => { const el = e.currentTarget; if (el.currentTime >= maxSeconds) { el.pause(); if (el.currentTime > maxSeconds) { el.currentTime = maxSeconds; } setCapped(true); } else { setCapped(false); } }; const onSeeking = (e: React.SyntheticEvent) => { const el = e.currentTarget; if (el.currentTime > maxSeconds) { el.currentTime = maxSeconds; } }; return (
); }