mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2026-06-05 20:15:31 -04:00
60 lines
1.3 KiB
TypeScript
60 lines
1.3 KiB
TypeScript
import { cn } from "@/lib/utils";
|
|
|
|
const Video = ({
|
|
src,
|
|
autoPlay,
|
|
className,
|
|
children,
|
|
...rest
|
|
}: Omit<Partial<React.ComponentProps<"video">>, "src"> & {
|
|
src: string | string[] | undefined;
|
|
}) => {
|
|
return (
|
|
<video
|
|
{...(typeof src === "string" ? { src } : {})}
|
|
{...(autoPlay
|
|
? {
|
|
autoPlay: true,
|
|
preload: "auto",
|
|
controls: false,
|
|
playsInline: true, // safari autoplay workaround
|
|
loop: true,
|
|
muted: true,
|
|
}
|
|
: {
|
|
autoPlay: false,
|
|
preload: "metadata",
|
|
controls: true,
|
|
playsInline: true,
|
|
})}
|
|
crossOrigin="anonymous"
|
|
className={cn("mx-auto block h-auto max-h-[500px] w-full", className)}
|
|
{...rest}
|
|
>
|
|
{Array.isArray(src) &&
|
|
src.map((file) => {
|
|
const extension = file.split(".").pop();
|
|
|
|
if (extension === "vtt") {
|
|
return (
|
|
<track
|
|
key={file}
|
|
kind="subtitles"
|
|
src={file}
|
|
srcLang="en"
|
|
label="English"
|
|
default
|
|
/>
|
|
);
|
|
} else {
|
|
return <source key={file} src={file} type={`video/${extension}`} />;
|
|
}
|
|
})}
|
|
|
|
{children}
|
|
</video>
|
|
);
|
|
};
|
|
|
|
export { Video };
|