Music Player is a fully functional audio player that collapses from an expanded player with artwork and queue into a compact pill, morphing between the two layouts with Framer Motion. It plays real audio files, tracks progress on a seekable bar, and manages a queue of tracks. The glassmorphic controls are props-driven. Built with React and Tailwind CSS. Use it for portfolio music demos, podcast landing pages, and anywhere a browser audio player needs to look designed rather than default.
Installation
Usage
import { MusicPlayer } from "@/components/ui/music-player";
import type { Track } from "@/components/ui/music-player";Basic Usage
const sampleTrack: Track = {
id: "1",
title: "Blinding Lights",
artist: "The Weeknd",
artwork: "/path/to/artwork.jpg",
duration: 200,
};
export default function BasicUsage() {
return <MusicPlayer currentTrack={sampleTrack} />;
}Real Audio Playback
Pass a url to play actual audio. When omitted, the player runs in simulated mode.
const sampleTrack: Track = {
id: "1",
title: "Blinding Lights",
artist: "The Weeknd",
artwork: "/path/to/artwork.jpg",
duration: 200,
url: "/path/to/audio.mp3", // local or remote URL
};
export default function RealAudio() {
return <MusicPlayer currentTrack={sampleTrack} />;
}Advanced Usage with Queue
export function AdvancedPlayer() {
const playlist: Track[] = [
{
id: "1",
title: "Sugar",
artist: "Maroon 5",
artwork: "/path/to/artwork1.jpg",
duration: 240,
url: "/path/to/audio1.mp3",
},
{
id: "2",
title: "Payphone",
artist: "Maroon 5",
artwork: "/path/to/artwork2.jpg",
duration: 210,
url: "/path/to/audio2.mp3",
},
];
return (
<MusicPlayer currentTrack={playlist[0]} queue={playlist} autoPlay={false} />
);
}Collapse / Expand
The player morphs between a compact pill bar and the full immersive card. The collapse button is in the top-left corner of the expanded card; click the thumbnail or title in the collapsed bar to expand again.
Keyboard Shortcuts
Shortcuts are active while the player has focus (click it or Tab to it).
| Key | Action |
|---|---|
Space | Play / Pause |
← / → | Seek -10s / +10s |
↑ / ↓ | Volume up / down |
Types
Track Interface
interface Track {
id: string;
title: string;
artist: string;
album?: string;
artwork: string;
duration: number;
url?: string;
}Props
MusicPlayer
Track Fields
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Unique identifier |
title | string | Yes | Track title |
artist | string | Yes | Artist name |
album | string | No | Album name (shown in expanded view if provided) |
artwork | string | Yes | Cover image URL (local or remote) |
duration | number | Yes | Track length in seconds |
url | string | No | Audio file URL. Enables real audio playback |
Props
MusicPlayer
| Prop | Type | Default | Description |
|---|---|---|---|
currentTrack | Track | undefined | Current track object containing metadata (falls back to internal default if not provided) |
queue | Track[] | [] | Array of tracks in the playlist queue |
currentIndex | number | 0 | Index of the current track in the queue |
className | string | "" | Additional CSS classes to apply to the component |
autoPlay | boolean | false | Whether to start playback automatically |
showEqualizer | boolean | true | Show animated equalizer bars next to the track title |
accentColor | string | "var(--foreground)" | Accent color for active playing waveform, toggle indicators, and active queue row |
onPlayPause | (isPlaying: boolean) => void | undefined | Callback triggered when play/pause is toggled |
onTimeChange | (time: number) => void | undefined | Callback triggered when playback time changes |
onTrackEnd | () => void | undefined | Callback triggered when track playback ends |
onTrackChange | (track: Track, index: number) => void | undefined | Callback triggered when track changes (next/previous) |
onVolumeChange | (volume: number) => void | undefined | Callback triggered when volume changes |
