import { IconButton, Slider, Tooltip } from 'modern-sk'; import { useAppDispatch, useAppSelector } from '../../hooks/useAppDispatch'; import { pause, resume, toggleMute, setVolume, toggleNowPlaying, toggleQueue } from '../../store/slices/player'; import { useAudioPlayer } from '../../hooks/useAudioPlayer'; import { formatDuration } from '../../lib/format'; import { getCoverUrl } from '../../api/endpoints/streaming'; export function PersistentPlayer() { const dispatch = useAppDispatch(); const { seek, playNext, playPrev } = useAudioPlayer(); const player = useAppSelector((s) => s.player); const queue = useAppSelector((s) => s.queue); const currentEntry = queue.entries[queue.currentIndex]; if (!currentEntry && !player.currentTrackId) { return (
Nothing playing
); } const artUrl = currentEntry?.albumArtUrl ? getCoverUrl(currentEntry.albumArtUrl) : undefined; const progressPercent = player.duration > 0 ? (player.position / player.duration) * 100 : 0; return (
{/* track info */}
dispatch(toggleNowPlaying())} > {artUrl ? ( ) : (
)}
{currentEntry?.title ?? '—'}
{currentEntry?.artistName ?? ''}
{/* controls + scrubber */}
player.isPlaying ? dispatch(pause()) : dispatch(resume())} aria-label={player.isPlaying ? 'Pause' : 'Play'} > {player.isPlaying ? '⏸' : '▶'}
{formatDuration(player.position * 1000)} seek(v)} style={{ flex: 1 }} /> {formatDuration(player.duration * 1000)}
{/* volume + queue */}
dispatch(toggleMute())} aria-label="Toggle mute"> {player.muted ? '🔇' : '🔊'} dispatch(setVolume(v))} style={{ width: '6rem' }} /> dispatch(toggleQueue())} aria-label="Toggle queue"> ≡
{/* progress bar at bottom */}
); }