Player full fonctionnel !

This commit is contained in:
2025-12-23 09:27:01 +01:00
parent 051d0431ce
commit e567a2c5ab

View File

@@ -49,19 +49,30 @@ export default function AudioPlayer({ track }: AudioPlayerProps) {
if (!audio) return if (!audio) return
const updateTime = () => setCurrentTime(audio.currentTime) const updateTime = () => setCurrentTime(audio.currentTime)
const updateDuration = () => setDuration(audio.duration) const updateDuration = () => {
if (audio.duration && isFinite(audio.duration)) {
setDuration(audio.duration)
}
}
const handleEnded = () => setIsPlaying(false) const handleEnded = () => setIsPlaying(false)
audio.addEventListener("timeupdate", updateTime) audio.addEventListener("timeupdate", updateTime)
audio.addEventListener("loadedmetadata", updateDuration) audio.addEventListener("loadedmetadata", updateDuration)
audio.addEventListener("durationchange", updateDuration)
audio.addEventListener("ended", handleEnded) audio.addEventListener("ended", handleEnded)
// Initialize duration if already loaded
if (audio.duration && isFinite(audio.duration)) {
setDuration(audio.duration)
}
return () => { return () => {
audio.removeEventListener("timeupdate", updateTime) audio.removeEventListener("timeupdate", updateTime)
audio.removeEventListener("loadedmetadata", updateDuration) audio.removeEventListener("loadedmetadata", updateDuration)
audio.removeEventListener("durationchange", updateDuration)
audio.removeEventListener("ended", handleEnded) audio.removeEventListener("ended", handleEnded)
} }
}, []) }, [track?.id])
const loadWaveform = async (trackId: string) => { const loadWaveform = async (trackId: string) => {
setIsLoadingWaveform(true) setIsLoadingWaveform(true)
@@ -195,30 +206,32 @@ export default function AudioPlayer({ track }: AudioPlayerProps) {
</div> </div>
) : waveformPeaks.length > 0 ? ( ) : waveformPeaks.length > 0 ? (
<div className="flex items-center h-full w-full gap-[1px] px-1"> <div className="flex items-center h-full w-full gap-[1px] px-1">
{waveformPeaks.map((peak: number, index: number) => { {waveformPeaks
const isPlayed = (index / waveformPeaks.length) * 100 <= progress .filter((_: number, index: number) => index % 4 === 0) // Take every 4th peak to reduce from 800 to 200
return ( .map((peak: number, index: number) => {
<div const originalIndex = index * 4
key={index} const isPlayed = (originalIndex / waveformPeaks.length) * 100 <= progress
className="flex items-center justify-center" return (
style={{
width: "2px",
height: "100%",
flexShrink: 0
}}
>
<div <div
className={`rounded-sm transition-colors ${ key={index}
isPlayed ? "bg-orange-500" : "bg-gray-400" className="flex-1 flex items-center justify-center"
}`}
style={{ style={{
width: "2px", minWidth: "1px",
height: `${Math.max(peak * 70, 4)}%`, maxWidth: "4px",
height: "100%",
}} }}
/> >
</div> <div
) className={`w-full rounded-sm transition-colors ${
})} isPlayed ? "bg-orange-500" : "bg-gray-400"
}`}
style={{
height: `${Math.max(peak * 70, 4)}%`,
}}
/>
</div>
)
})}
</div> </div>
) : ( ) : (
<div className="flex items-center h-full w-full px-2"> <div className="flex items-center h-full w-full px-2">