-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae8b003
commit 635264e
Showing
2 changed files
with
60 additions
and
10 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,53 @@ | ||
import React from "react"; | ||
|
||
interface VideoDemoProps { | ||
src: string; | ||
type: "youtube" | "local"; | ||
title?: string; | ||
autoplay?: boolean; | ||
} | ||
|
||
export const VideoDemo: React.FC<VideoDemoProps> = ({ | ||
src, | ||
type, | ||
title, | ||
autoplay = false, | ||
}) => { | ||
if (type === "youtube") { | ||
const youtubeParams = new URLSearchParams({ | ||
autoplay: autoplay ? "1" : "0", | ||
controls: "0", | ||
showinfo: "0", | ||
rel: "0", | ||
loop: "1", | ||
playlist: src.split("/").pop() || "", | ||
}).toString(); | ||
|
||
const embedUrl = `${src}?${youtubeParams}`; | ||
|
||
return ( | ||
<iframe | ||
className="w-full h-full" | ||
src={embedUrl} | ||
title={title || "YouTube video player"} | ||
frameBorder="0" | ||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" | ||
referrerPolicy="strict-origin-when-cross-origin" | ||
allowFullScreen | ||
></iframe> | ||
); | ||
} else { | ||
return ( | ||
<video | ||
className="w-full h-full object-cover" | ||
autoPlay={autoplay} | ||
loop | ||
muted | ||
playsInline | ||
> | ||
<source src={src} type="video/mp4" /> | ||
Your browser does not support the video tag. | ||
</video> | ||
); | ||
} | ||
}; |
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