'use client' import React, { useEffect, useRef, useState } from 'react'; import { IoIosShareAlt } from 'react-icons/io'; import { Wand, Heart, MessageCircle, Bookmark } from 'lucide-react'; interface VideoPlayerProps { sources: string[]; className?: string; } const ICON_SIZE = 28; export default function VideoPlayer({ sources, className = "" }: VideoPlayerProps) { const videoRef = useRef(null); const [currentSourceIndex, setCurrentSourceIndex] = useState(0); useEffect(() => { const videoElement = videoRef.current; if (!videoElement) return; // Handle video ended event to switch to the next video const handleVideoEnded = () => { // Fade out if (videoElement) { videoElement.classList.add('opacity-0'); // Wait for fade out, then change source and fade in setTimeout(() => { setCurrentSourceIndex((prevIndex) => (prevIndex + 1) % sources.length); }, 300); } }; videoElement.addEventListener('ended', handleVideoEnded); // Clean up event listener return () => { videoElement.removeEventListener('ended', handleVideoEnded); }; }, [sources.length]); // When the current source index changes, load and play the new video useEffect(() => { const videoElement = videoRef.current; if (!videoElement) return; videoElement.load(); videoElement.play().catch(error => { console.error("Error playing video:", error); }); // Fade in after source change setTimeout(() => { videoElement.classList.remove('opacity-0'); }, 50); }, [currentSourceIndex]); return (
{/* TikTok-style icons */}
); }