Skip to content

Commit

Permalink
fix: hooks to fetch duration
Browse files Browse the repository at this point in the history
  • Loading branch information
sujal-into committed Nov 22, 2024
1 parent fc32d31 commit 19a7b6e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/hooks/feed/useVideoAudioDuration.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useQuery } from "@tanstack/react-query";

import { getVideoDurationFromURL } from "@/utils/video";

export const useVideoAudioDuration = (url: string, duration: number) => {
const { data, isLoading } = useQuery(
["getVideoDuration", url],
async () => {
if (duration) return duration;

try {
const duration = await getVideoDurationFromURL(url);
console.log(duration);
return duration;
} catch (error) {
console.log(error);
return 0;
}
},
{ staleTime: Infinity },
);

return { duration: data || 0, isLoading };
};

0 comments on commit 19a7b6e

Please sign in to comment.