diff --git a/src/App.jsx b/src/App.jsx index bfaeb2c..a1ba486 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1903,6 +1903,8 @@ function SongOfDayCard({ onRetry, songOfDay }) { const audioRef = useRef(null) const [isPreviewPlaying, setIsPreviewPlaying] = useState(false) const [previewError, setPreviewError] = useState('') + const [previewVolume, setPreviewVolume] = useState(0.18) + const [isPreviewMuted, setIsPreviewMuted] = useState(false) const message = songOfDay.status === 'error' ? songOfDay.error @@ -1913,6 +1915,29 @@ function SongOfDayCard({ onRetry, songOfDay }) { setPreviewError('') }, [track?.id, track?.preview_url]) + useEffect(() => { + const audio = audioRef.current + if (!audio) return + audio.volume = previewVolume + audio.muted = isPreviewMuted + }, [isPreviewMuted, previewVolume, track?.preview_url]) + + useEffect(() => { + const audio = audioRef.current + if (!track?.preview_url || !audio) return + + audio.volume = previewVolume + audio.muted = isPreviewMuted + audio.play() + .then(() => { + setIsPreviewPlaying(true) + setPreviewError('') + }) + .catch(() => { + setIsPreviewPlaying(false) + }) + }, [isPreviewMuted, previewVolume, track?.preview_url]) + function togglePreview() { const audio = audioRef.current if (!audio) return @@ -1950,19 +1975,40 @@ function SongOfDayCard({ onRetry, songOfDay }) {

{previewError}

) : null} {track.preview_url ? ( -