I'm trying to retrieve the .mp4 file to render inside as a source to the HTML5 tag <video src={videoUrl} />
I can see all the properties of the video with the passed ID but nothing to the direct file itself so it can play within the src of the video tag.
How can I access the file to play through my player? I don't want to use the oEmbed or Iframe due to performance reasons.
export const getVimeoData = async (id: string) => {
const vim_res = await fetch(`https://api.vimeo.com/videos/${id}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env.VIMEO_TOKEN}`,
"grant_type": "client_credentials",
},
})
.then((res) => res.json())
.then((data) => {
console.log('data :>> ', data);
})
.catch((err) => console.log(err));
return vim_res;
};
This code uses the videos/{video_id}/files endpoint to fetch the video files associated with the Vimeo video. It then searches for the file with the desired quality (e.g., 'hd') and returns its link.
Remember, the file quality might vary, so you might need to adjust the logic for selecting the desired quality based on your requirements.
Once you have the direct URL to the video file (videoFile.link), you can set it as the src attribute for the tag in your HTML: