Skip to content
This repository was archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
feat: use vimeo player instance to add custom icon and control video (#…
Browse files Browse the repository at this point in the history
…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
YounixM authored May 14, 2024
1 parent 7eb5fb5 commit 32311ca
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 12 deletions.
52 changes: 52 additions & 0 deletions src/components/VimeoPlayer/VimeoPlayer.tsx
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;
15 changes: 3 additions & 12 deletions src/modules/index-header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import React, { useEffect, useRef, useState } from "react";
import Player from "@vimeo/player";
import React from "react";
import SubHeading from "../../components/ui/SubHeading";
import Hero from "../../components/ui/Hero";
import Button from "../../components/ui/Button";
import ReactModal from "react-modal";
import { LiteYoutubeEmbed } from "react-lite-yt-embed";
import VimeoPlayer from "../../components/VimeoPlayer/VimeoPlayer";

export const Header = () => {
return (
Expand Down Expand Up @@ -44,14 +42,7 @@ export const Header = () => {
<div className="w-100 mx-auto">
<div className="product-explainer-video hero-figure p-3 rounded-lg">
<div className="embed-container">
<iframe
className="product-explainer-video-frame"
src="https://player.vimeo.com/video/944340217"
frameborder="0"
webkitAllowFullScreen
mozallowfullscreen
allowFullScreen
></iframe>
<VimeoPlayer videoId="944340217" />
</div>
</div>
</div>
Expand Down

0 comments on commit 32311ca

Please sign in to comment.