opensourceui
GitHubTwitter/X
  1. Home
  2. Components
  3. Audio
  4. Music Player
Back to Audio

Components / Audio

Music Player

Free Audio React component — MusicPlayerCard. MIT licensed, copy-paste ready for Next.js and Tailwind CSS.

Full dark player card with cover art, album info, progress scrubber with times, and transport controls. Not a bar — the whole now-playing screen.

Preview

Midnight Dreams

Midnight Dreams

The Weekend · After Hours

1:243:42

Setup

How to use

Free for personal and commercial use. No UI attribution required. Include the MIT copyright notice when copying component source into your project. Read the MIT license.

  1. 1

    Run in your terminal:

    $npm install clsx tailwind-merge lucide-react
  2. 2

    Copy lib/cn.ts below. Skip if you already have cn().

  3. 3

    Copy the code below and create components/audio/music-player-card.tsx in your project.

  4. 4

    Import and render:

    Example

    import { MusicPlayerCard } from "@/components/audio/music-player-card";

    <MusicPlayerCard />

lib/cn.ts

1
2
3
4
5
6
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
 
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

components/audio/music-player-card.tsx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
"use client";
 
import { forwardRef, useState, type ComponentPropsWithoutRef } from "react";
 
import Image from "next/image";
 
import { cn } from "@/lib/cn";
 
import { Play, Pause, SkipForward, SkipBack } from "lucide-react";
 
export type MusicPlayerCardProps = Readonly<
{
coverImage?: string;
title?: string;
artist?: string;
album?: string;
currentTime?: string;
duration?: string;
progress?: number;
defaultPlaying?: boolean;
} & ComponentPropsWithoutRef<"div">
>;
 
// Production-ready Music Player component — styled with Tailwind CSS.
export const MusicPlayerCard = forwardRef<HTMLDivElement, MusicPlayerCardProps>(
(
{
className,
coverImage = "/wallpaper-3.png",
title = "Midnight Dreams",
artist = "The Weekend",
album = "After Hours",
currentTime = "1:24",
duration = "3:42",
progress = 42,
defaultPlaying = true,
...props
},
ref,
) => {
const [playing, setPlaying] = useState(defaultPlaying);
 
return (
<div
ref={ref}
data-slot="music-player-card"
className={cn(
"w-72 overflow-hidden rounded-2xl bg-neutral-950 font-sans shadow-lg",
className,
)}
{...props}
>
{/* Cover */}
<div data-slot="music-player-card-cover" className="relative h-36">
<Image
src={coverImage}
alt={title}
fill
sizes="288px"
className="object-cover opacity-80"
/>
 
<div
data-slot="music-player-card-overlay"
className="absolute inset-0 bg-linear-to-t from-neutral-950 via-neutral-950/40 to-transparent"
/>
</div>
 
<div
data-slot="music-player-card-content"
className="relative -mt-6 p-4"
>
{/* Track Info */}
<div data-slot="music-player-card-info">
<h3 className="text-sm font-semibold text-white">{title}</h3>
 
<p className="text-[11px] text-neutral-500">
{artist} · {album}
</p>
</div>
 
{/* Progress */}
<div data-slot="music-player-card-progress" className="mt-4">
<div className="h-1 overflow-hidden rounded-full bg-neutral-800">
<div
className="relative h-full rounded-full bg-emerald-500"
style={{
width: `${Math.min(Math.max(progress, 0), 100)}%`,
}}
>
<div className="absolute top-1/2 right-0 h-2.5 w-2.5 -translate-y-1/2 rounded-full bg-white shadow" />
</div>
</div>
 
<div className="mt-1 flex justify-between">
<span className="font-mono text-[9px] text-neutral-600">
{currentTime}
</span>
 
<span className="font-mono text-[9px] text-neutral-600">
{duration}
</span>
</div>
</div>
 
{/* Controls */}
<div
data-slot="music-player-card-controls"
className="mt-3 flex items-center justify-center gap-5"
>
<button
type="button"
aria-label="Previous track"
className="cursor-pointer text-lg text-neutral-500 transition-colors hover:text-white"
>
<SkipBack size={14} />
</button>
 
<button
type="button"
aria-label={playing ? "Pause" : "Play"}
onClick={() => setPlaying((prev) => !prev)}
className="flex h-10 w-10 cursor-pointer items-center justify-center rounded-full bg-white transition-transform hover:scale-105"
>
{playing ? (
<Pause size={14} fill="black" />
) : (
<Play size={14} fill="black" />
)}
</button>
 
<button
type="button"
aria-label="Next track"
className="cursor-pointer text-lg text-neutral-500 transition-colors hover:text-white"
>
<SkipForward size={14} />
</button>
</div>
</div>
</div>
);
},
);
 
MusicPlayerCard.displayName = "MusicPlayerCard";
PreviousNext

On this

page

Jump to a section on this page.

  • lib/cn.ts
  • components/audio/music-player-card.tsx

Sponsor spot · demo preview

Logo

Your brand name

Your tagline or category

A short pitch about your product or service goes here. This is a preview of how sponsor cards will look in this sidebar.

Your call to action

This slot is available. Sponsor Opensource UI and reach developers browsing components every day.