This repository was archived by the owner on Jun 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use vimeo player instance to add custom icon and control video (#…
…1729) * feat: use vimeo player instance to add custom icon and control video * feat: import vimeo player only if client is browser
- Loading branch information
Showing
2 changed files
with
55 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React, { useEffect, useRef, useState } from "react"; | ||
import useIsBrowser from "@docusaurus/useIsBrowser"; | ||
|
||
const VimeoPlayer = ({ videoId }) => { | ||
const playerRef = useRef(null); | ||
const [isPlaying, setIsPlaying] = useState(false); | ||
let player = null; | ||
const isBrowser = useIsBrowser(); | ||
|
||
useEffect(() => { | ||
const loadVimeoPlayer = async () => { | ||
try { | ||
if (isBrowser && videoId) { | ||
const { default: Player } = await import("@vimeo/player"); | ||
|
||
player = new Player(playerRef.current, { | ||
url: `https://vimeo.com/${videoId}`, | ||
}); | ||
} | ||
} catch (error) { | ||
console.error("Error loading Vimeo Player:", error); | ||
} | ||
}; | ||
|
||
loadVimeoPlayer(); | ||
}, [isBrowser, videoId]); | ||
|
||
const handlePlay = () => { | ||
if (!isPlaying && player && typeof player.play === "function") { | ||
player.play(); | ||
setIsPlaying(true); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div ref={playerRef} /> | ||
{!isPlaying && ( | ||
<div onClick={handlePlay}> | ||
<div className="cursor-pointer play-container w-16 h-16 md:w-24 md:h-24 rounded-full bg-primary-500 flex justify-center items-center focus-visible:outline-none"> | ||
<img | ||
src="/img/landing/play-icon.webp" | ||
className="w-6 h-6 md:w-10 md:h-10" | ||
/> | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default VimeoPlayer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters