| 1 |
import { useRef, useState } from 'react'; |
| 2 |
|
| 3 |
export const VideoPlayer = ({ path, poster, className = null }) => { |
| 4 |
const videoRef = useRef(); |
| 5 |
const [playing, setPlaying] = useState(false); |
| 6 |
return ( |
| 7 |
<div |
| 8 |
className={`relative ${className}`} |
| 9 |
style={{ |
| 10 |
backgroundImage: !playing ? `url(${poster})` : 'none', |
| 11 |
backgroundSize: 'contain', |
| 12 |
backgroundPosition: 'center', |
| 13 |
backgroundRepeat: 'no-repeat', |
| 14 |
}} |
| 15 |
> |
| 16 |
<video |
| 17 |
ref={videoRef} |
| 18 |
id="video-player" |
| 19 |
className="h-auto max-h-[min(50vh,400px)] w-full object-contain" |
| 20 |
playsInline |
| 21 |
muted |
| 22 |
autoPlay |
| 23 |
poster={poster} |
| 24 |
loop |
| 25 |
onPlay={() => setPlaying(true)} |
| 26 |
> |
| 27 |
<source src={path} type="video/webm" /> |
| 28 |
Your browser does not support the video tag. |
| 29 |
</video> |
| 30 |
</div> |
| 31 |
); |
| 32 |
}; |
| 33 |
|