"use client";
import dynamic from "next/dynamic";
import { useState } from "react";
import "react-h5-audio-player/lib/styles.css";
import { z } from "zod";
import { Loader, Status } from "~/components/Global";
import useLoading from "~/hooks/useLoading";
import { Schema_File } from "~/types/schema";
import { CreateDownloadToken } from "actions";
const Plyr = dynamic(() => import("plyr-react"), {
ssr: false,
loading: () => ,
});
type Props = {
file: z.infer;
};
export default function PreviewAudio({ file }: Props) {
const [audioSrc, setAudioSrc] = useState("");
const [error, setError] = useState("");
const loading = useLoading(async () => {
try {
if (!file.encryptedWebContentLink) {
setError("No audio to preview");
return;
}
const token = await CreateDownloadToken();
setAudioSrc(`/api/stream/${file.encryptedId}?token=${token}`);
} catch (error) {
const e = error as Error;
console.error(e);
setError(e.message);
}
}, [file]);
return (
{loading ? (
) : error ? (
) : (
)}
);
}