import React, { useState, useRef, useEffect } from 'react'; import { Play, Pause, Volume2, VolumeX } from 'lucide-react'; interface AudioPlayerProps { src: string; } export default function AudioPlayer({ src }: AudioPlayerProps) { const [isPlaying, setIsPlaying] = useState(false); const [duration, setDuration] = useState(0); const [currentTime, setCurrentTime] = useState(0); const [isMuted, setIsMuted] = useState(false); const audioRef = useRef(null); const progressBarRef = useRef(null); useEffect(() => { setIsPlaying(false); setCurrentTime(0); }, [src]); const togglePlay = () => { if (!audioRef.current) return; if (isPlaying) { audioRef.current.pause(); } else { audioRef.current.play(); } setIsPlaying(!isPlaying); }; const handleTimeUpdate = () => { if (!audioRef.current) return; setCurrentTime(audioRef.current.currentTime); }; const handleLoadedMetadata = () => { if (!audioRef.current) return; setDuration(audioRef.current.duration); }; const handleProgressChange = (e: React.ChangeEvent) => { if (!audioRef.current) return; const newTime = parseFloat(e.target.value); audioRef.current.currentTime = newTime; setCurrentTime(newTime); }; const toggleMute = () => { if (!audioRef.current) return; audioRef.current.muted = !isMuted; setIsMuted(!isMuted); }; const formatTime = (time: number) => { if (isNaN(time)) return '0:00'; const minutes = Math.floor(time / 60); const seconds = Math.floor(time % 60); return `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`; }; return (
); }