"use client"; import { useState, useRef, useEffect } from 'react'; import { X, Play, Pause, Maximize, Minimize, Volume2, VolumeX } from 'lucide-react'; interface InlineVideoPlayerProps { video: { id: number; title: string; path: string; size: number; thumbnail: string; }; isOpen: boolean; onClose: () => void; scrollPosition?: number; } export default function InlineVideoPlayer({ video, isOpen, onClose, scrollPosition }: InlineVideoPlayerProps) { const [isPlaying, setIsPlaying] = useState(false); const [isFullscreen, setIsFullscreen] = useState(false); const [isMuted, setIsMuted] = useState(false); const [volume, setVolume] = useState(1); const [currentTime, setCurrentTime] = useState(0); const [duration, setDuration] = useState(0); const [isVisible, setIsVisible] = useState(false); const [showControls, setShowControls] = useState(true); const videoRef = useRef(null); useEffect(() => { if (isOpen) { setIsVisible(true); } else { setIsVisible(false); } }, [isOpen]); useEffect(() => { if (isOpen && videoRef.current) { videoRef.current.src = `/api/stream/${video.id}`; videoRef.current.load(); // Auto-play when video is loaded videoRef.current.addEventListener('loadeddata', () => { if (videoRef.current) { videoRef.current.play().then(() => { setIsPlaying(true); }).catch((error) => { console.log('Auto-play prevented by browser:', error); // Auto-play might be blocked by browser, that's okay }); } }); } }, [isOpen, video.id]); const handlePlayPause = () => { if (videoRef.current) { if (isPlaying) { videoRef.current.pause(); } else { videoRef.current.play(); } setIsPlaying(!isPlaying); } }; const handleMute = () => { if (videoRef.current) { videoRef.current.muted = !isMuted; setIsMuted(!isMuted); } }; const handleVolumeChange = (e: React.ChangeEvent) => { if (videoRef.current) { const newVolume = parseFloat(e.target.value); videoRef.current.volume = newVolume; setVolume(newVolume); setIsMuted(newVolume === 0); } }; const handleTimeUpdate = () => { if (videoRef.current) { setCurrentTime(videoRef.current.currentTime); } }; const handleLoadedMetadata = () => { if (videoRef.current) { setDuration(videoRef.current.duration); } }; const handleProgressClick = (e: React.MouseEvent) => { if (videoRef.current) { const rect = e.currentTarget.getBoundingClientRect(); const clickX = e.clientX - rect.left; const newTime = (clickX / rect.width) * duration; videoRef.current.currentTime = newTime; setCurrentTime(newTime); } }; const formatTime = (time: number) => { const minutes = Math.floor(time / 60); const seconds = Math.floor(time % 60); return `${minutes}:${seconds.toString().padStart(2, '0')}`; }; useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape') { onClose(); } if (e.key === ' ') { e.preventDefault(); handlePlayPause(); } }; if (isOpen) { document.addEventListener('keydown', handleKeyDown); // Prevent body scroll when player is open document.body.style.overflow = 'hidden'; } return () => { document.removeEventListener('keydown', handleKeyDown); // Restore body scroll when player is closed document.body.style.overflow = 'unset'; }; }, [isOpen, onClose]); if (!isOpen) return null; return (
{/* Header */}

{video.title}

{/* Video Player */}
{/* Video Overlay Controls */}
{/* Center Play Button */}
{/* Bottom Controls */}
{/* Progress Bar */}
{/* Control Buttons */}
{formatTime(currentTime)} / {formatTime(duration)}
{Math.round(video.size / 1024 / 1024)} MB
{/* Video info below player */}

{video.title}

{video.path}

File size: {Math.round(video.size / 1024 / 1024)} MB

); }