2023-12-16 14:55:56 +00:00
|
|
|
import { Box, SxProps } from "@mui/material";
|
|
|
|
|
|
|
|
interface Props {
|
2024-01-05 17:00:30 +00:00
|
|
|
videoUrl: string;
|
|
|
|
containerSX?: SxProps;
|
2023-12-16 14:55:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function YoutubeEmbedIframe({ videoUrl, containerSX }: Props) {
|
2024-01-05 17:00:30 +00:00
|
|
|
const extractYoutubeVideoId =
|
|
|
|
/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/gi;
|
|
|
|
const videoId = extractYoutubeVideoId.exec(videoUrl)?.[1];
|
|
|
|
// if (!videoId) return null;
|
2023-12-16 14:55:56 +00:00
|
|
|
|
2024-01-05 17:00:30 +00:00
|
|
|
const embedUrl = `https://www.youtube.com/embed/${videoId}?controls=0&autoplay=1&modestbranding=0&showinfo=0&disablekb=1&mute=1&loop=1`;
|
|
|
|
// https://www.youtube.com/shorts/9VgqBPd6RPA
|
|
|
|
// https://www.youtube.com/watch?v=I2N8hTHhvGY
|
|
|
|
return (
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
width: "100%",
|
|
|
|
height: "100%",
|
|
|
|
pointerEvents: "none",
|
|
|
|
"& iframe": {
|
|
|
|
width: "100%",
|
|
|
|
height: "100%",
|
|
|
|
},
|
|
|
|
...containerSX,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Box
|
|
|
|
component="video"
|
|
|
|
sx={{
|
|
|
|
width: "100%",
|
|
|
|
height: "100%",
|
|
|
|
}}
|
|
|
|
autoPlay
|
|
|
|
muted
|
|
|
|
src={videoUrl}
|
|
|
|
/>
|
|
|
|
{/* <iframe
|
|
|
|
src={embedUrl}
|
|
|
|
title="YouTube video player"
|
|
|
|
frameBorder="0"
|
|
|
|
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
|
|
|
allowFullScreen
|
|
|
|
/> */}
|
|
|
|
</Box>
|
|
|
|
);
|
2023-12-16 14:55:56 +00:00
|
|
|
}
|