import 'vidstack/styles/base.css' import { cn } from '@/lib/utils' import { MediaPlayer, MediaOutlet, useMediaRemote, useMediaStore } from '@vidstack/react' import { Play } from 'lucide-react' import { useState, useRef } from 'react' /** Video embed component using vidstack. Supports poster overlays, gif-style autoplay, and lazy loading. */ export const Video = ({ src, poster, aspectRatio, className, gifStyle = false, title, }: { src: string poster?: string aspectRatio?: number gifStyle?: boolean className?: string title?: string }) => { const [panelDismissed, setPanelDismissed] = useState(false) const mediaPlayerRef = useRef(null) const remote = useMediaRemote(mediaPlayerRef) const { duration } = useMediaStore(mediaPlayerRef) const durationString = duration ? `${Math.floor(duration / 60)}:${Math.floor(duration % 60)} min` : null return ( {gifStyle ? ( // Capture mouse events, they broke scrolling on iOS
) : panelDismissed ? null : ( // Overlay with play button and poster image
{ remote.startLoading() }} onClick={() => { remote.play() setPanelDismissed(true) }} onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault() remote.play() setPanelDismissed(true) } }} >
{title && {title}} {durationString && {durationString}}
)} ) }