What We're Building
An interactive music player featuring:
- Collapsed song card that springs into an expansive player on click
- Spinning vinyl record with radial groove shaders that morphs away in lyrics mode
- Real-time 6-band audio frequency visualizer using Web Audio API
- Synced LRC lyrics with spring scrolling and an animated tooltip toggle
- Physics-based elastic slider for scrubbing with boundary decay
- Slot-machine style rolling digit counter for playback time
In a hurry? Jump straight to the Full Component Code.
Deep Dive: How the Core Features Work
Before jumping into the full code, let's explore the key mechanics that make this UI feel so responsive and alive:
1. Collapsed vs Expanded Card Animation
The song list starts as a compact 72px card and springs into an expansive 450px player on click. AnimatePresence with mode="sync" ensures seamless transitions between the collapsed preview and the full player interface:

app/components/music-player.tsx<motion.div
animate={{
height: isOpen ? 450 : 72,
borderRadius: isOpen ? 32 : 20,
}}
transition={{ type: "spring", stiffness: 420, damping: 30 }}
whileTap={{ scale: 0.98 }}
onClick={() => toggleSong(index)}
className="relative w-full cursor-pointer overflow-hidden bg-[var(--tooltip-surface)] select-none"
>
<AnimatePresence mode="sync">
{!isOpen ? (
<motion.div key="collapsed" initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }}>
</motion.div>
) : (
<motion.div key="expanded" initial={{ opacity: 0, scale: 0.96 }} animate={{ opacity: 1, scale: 1 }} exit={{ opacity: 0, scale: 0.95 }}>
</motion.div>
)}
</AnimatePresence>
</motion.div>- Height & Radius: Animates simultaneously between
72px(rounded-20) and450px(rounded-32). - Tactile Feedback:
whileTap={{ scale: 0.98 }}gives a satisfying click depression.
2. Vinyl Record & Lyrics Mode Morphing
The vinyl record uses an infinite rotation with a repeating radial gradient to simulate real vinyl record grooves:

app/components/music-player.tsx<motion.div
animate={{
y: isLyricsMode ? -240 : 0,
opacity: isLyricsMode ? 0 : 1,
scale: isLyricsMode ? 0.75 : 1,
}}
transition={{ type: "spring", stiffness: 320, damping: 30 }}
className="pointer-events-none absolute left-1/2 top-0 w-[380px] -translate-x-1/2 -translate-y-1/2 z-10"
>
<motion.div
animate={{ rotate: 360 }}
transition={{ duration: 20, repeat: Infinity, ease: "linear" }}
className="relative aspect-square w-full rounded-full overflow-hidden"
>
<img src={song.image} className="absolute inset-0 h-full w-full object-cover" />
<div
className="absolute inset-0"
style={{
backgroundImage:
"repeating-radial-gradient(circle, transparent 0 4px, rgba(0,0,0,0.12) 4px 4.5px)",
}}
/>
<div className="absolute left-1/2 top-1/2 h-[18%] w-[18%] -translate-x-1/2 -translate-y-1/2 rounded-full bg-[#1c1c1f]">
<div className="absolute left-1/2 top-1/2 h-[8%] w-[8%] -translate-x-1/2 -translate-y-1/2 rounded-full bg-black" />
</div>
</motion.div>
</motion.div>When lyrics mode is activated, the vinyl slides up (y: -240), scales down to 0.75, and fades out. At the same time, the Equalizer smoothly shifts its top margin up (marginTop: 16 vs 220), dynamically clearing space for the lyrics.
3. Web Audio API Frequency Equalizer
We connect an AudioContext and AnalyserNode to the <audio> element to extract real-time FFT frequency bytes:
app/components/music-player.tsxconst ctx = new AudioContext();
const source = ctx.createMediaElementSource(audio);
const analyser = ctx.createAnalyser();
analyser.fftSize = 256;
analyser.smoothingTimeConstant = 0.55;
source.connect(analyser);
analyser.connect(ctx.destination);In a requestAnimationFrame loop, frequency data is sampled and mapped into 6 symmetric frequency bands:
- Low bass (
bands 1-6) - Mid-range (
bands 7-16) - High vocal (
bands 17-45)
When playback pauses, a gentle sine wave keeps the bars subtly breathing in idle state.
4. Synced Lyrics with Tooltip Button
LRC timestamped files are parsed and matched against the active playback time. Active lyrics scroll via a spring transition with a gradient mask for edge blur:

The toggle button at the bottom-left includes an animated tooltip:
app/components/music-player.tsx<span className="lyrics-toggle relative flex items-center justify-center">
<button
type="button"
onClick={() => setIsLyricsMode((prev) => !prev)}
className="flex h-7 w-7 items-center justify-center transition-transform active:scale-90 cursor-pointer outline-none"
aria-label={isLyricsMode ? "Close" : "Lyrics"}
>
<LyricsIcon
className={
isLyricsMode
? "h-[18px] w-[18px] text-[var(--text)] transition-colors duration-200"
: "h-[18px] w-[18px] text-[var(--text-secondary)] hover:text-[var(--text)] opacity-40 hover:opacity-100 transition-colors duration-200"
}
/>
</button>
<span className="tooltip-bubble" role="tooltip">
{isLyricsMode ? "Close" : "Lyrics"}
</span>
</span>5. Elastic Slider with Sigmoid Decay
Instead of a rigid progress bar, dragging past track boundaries applies a sigmoid decay formula:
app/components/music-player.tsxfunction decay(value: number, max: number) {
if (max === 0) return 0;
const entry = value / max;
const sigmoid = 2 * (1 / (1 + Math.exp(-entry)) - 0.5);
return sigmoid * max;
}This creates natural rubber-band resistance that bounces back when released.
6. Slot-Machine Rolling Timer
Timer numbers are rendered on vertical strips with digits 0123456789. When a digit increments, CSS translateY rolls the strip with an ease-out curve, mirroring mechanical odometer counters.
Project Structure
Here is how the project is organized. You only need 3 files:
Project Structureapp/
├── components/
│ └── music-player.tsx # All-in-one music player component
├── music/
│ └── page.tsx # Page to render the player
└── music-data.ts # Song data and types
public/
└── music/
├── song.mp3 # Audio files
└── lyric/
└── song.lrc # LRC lyric filesInstall the required animation library:
Terminalnpm install framer-motionFull Component Code
Ready to drop this into your project? Copy and paste the 3 files below:
1. Song Data
app/music-data.tsexport type Song = {
title: string;
artist: string;
href?: string;
image: string;
duration: number;
audio: string;
lyric?: string;
};
export const SONGS: Song[] = [
{
title: "Ivy",
artist: "Frank Ocean",
image: "https://image-cdn-ak.spotifycdn.com/image/ab67616d0000b273c5649add07ed3720be9d5526",
duration: 249,
audio: "/music/ivy.mp3",
lyric: "/music/lyric/ivy.lrc",
},
{
title: "Who Knows",
artist: "Daniel Caesar",
image: "https://image-cdn-ak.spotifycdn.com/image/ab67616d0000b2732bad6e56e77d5bef0aa3f2dc",
duration: 172,
audio: "/music/who-knows.mp3",
lyric: "/music/lyric/who-knows.lrc",
},
];2. Music Player Component
app/components/music-player.tsx"use client";
import { useCallback, useEffect, useRef, useState, type RefObject } from "react";
import {
AnimatePresence,
animate,
motion,
useMotionValue,
useMotionValueEvent,
useTransform,
} from "framer-motion";
import type { Song } from "../music-data";
export type LyricLine = {
time: number;
text: string;
};
export function parseLrc(lrcText: string): LyricLine[] {
const lines = lrcText.split("
");
const result: LyricLine[] = [];
const timeRegex = /[(d{2}):(d{2})(?:.(d{2,3}))?]/g;
for (const line of lines) {
const trimmed = line.trim();
if (!trimmed || /^[(ti|ar|al|by|offset|length):/i.test(trimmed)) continue;
const matches = [...trimmed.matchAll(timeRegex)];
if (matches.length > 0) {
const text = trimmed.replace(timeRegex, "").trim();
for (const match of matches) {
const min = parseInt(match[1], 10);
const sec = parseInt(match[2], 10);
const ms = match[3] ? parseInt(match[3].padEnd(3, "0").slice(0, 3), 10) : 0;
result.push({ time: min * 60 + sec + ms / 1000, text: text || "♪" });
}
}
}
return result.sort((a, b) => a.time - b.time);
}
function formatTime(totalSeconds: number) {
const clamped = Math.max(0, totalSeconds);
const minutes = Math.floor(clamped / 60);
const seconds = Math.floor(clamped % 60);
return `${minutes}:${String(seconds).padStart(2, "0")}`;
}
function useAnimatedTime(audioRef: RefObject<HTMLAudioElement | null>) {
const [displayTime, setDisplayTime] = useState(0);
useEffect(() => {
let raf = 0;
const tick = () => {
raf = requestAnimationFrame(tick);
const audio = audioRef.current;
if (audio && Number.isFinite(audio.currentTime)) {
setDisplayTime(audio.currentTime);
}
};
raf = requestAnimationFrame(tick);
return () => cancelAnimationFrame(raf);
}, [audioRef]);
return displayTime;
}
const DIGIT_HEIGHT = 1.1;
function RollingDigit({ char }: { char: string }) {
const stripRef = useRef<HTMLDivElement>(null);
const offsetRef = useRef<number | null>(null);
useEffect(() => {
const el = stripRef.current;
if (!el) return;
const digit = parseInt(char, 10);
if (Number.isNaN(digit)) return;
const prev = offsetRef.current ?? 0;
let target = prev;
if (digit !== prev % 10) {
const delta = (digit - (prev % 10) + 10) % 10;
target = prev + delta;
if (target >= 30) target -= 20;
}
offsetRef.current = target;
el.style.transition = "transform 0.35s cubic-bezier(0.22, 1, 0.36, 1)";
el.style.transform = `translateY(-${target * DIGIT_HEIGHT}em)`;
}, [char]);
return (
<span className="relative inline-flex h-[1.1em] overflow-hidden">
<span className="invisible select-none flex items-center h-[1.1em] leading-none px-[0.5px]" aria-hidden="true">
0
</span>
<div ref={stripRef} className="absolute left-0 top-0 w-full">
{"012345678901234567890123456789".split("").map((d, i) => (
<span key={i} className="flex h-[1.1em] items-center justify-center leading-none px-[1.5px]">
{d}
</span>
))}
</div>
</span>
);
}
function RollingTime({ value }: { value: number }) {
const str = formatTime(value);
return (
<span className="inline-flex items-center h-[1.1em]">
{str.split("").map((ch, i) =>
ch === ":" ? (
<span key={i} className="inline-flex items-center justify-center px-[1px] select-none h-[1.1em] leading-none">
:
</span>
) : (
<RollingDigit key={i} char={ch} />
)
)}
</span>
);
}
function Equalizer({
playing,
analyserRef,
}: {
playing: boolean;
analyserRef: RefObject<AnalyserNode | null>;
}) {
const barRefs = useRef<(HTMLDivElement | null)[]>([]);
const dataRef = useRef<Uint8Array | null>(null);
const heightsRef = useRef<number[]>([6, 6, 6, 6, 6, 6]);
useEffect(() => {
let raf = 0;
const loop = () => {
raf = requestAnimationFrame(loop);
const analyser = analyserRef.current;
const bars = barRefs.current;
if (!analyser || bars.length === 0 || bars.some((b) => !b)) return;
if (!playing) {
const now = Date.now();
bars.forEach((bar, i) => {
if (!bar) return;
const idle = 6 + Math.sin(now / 1100 + i * 1.7) * 4;
heightsRef.current[i] = idle;
bar.style.height = `${idle.toFixed(1)}px`;
});
return;
}
if (!dataRef.current) dataRef.current = new Uint8Array(analyser.frequencyBinCount);
analyser.getByteFrequencyData(dataRef.current);
const data = dataRef.current;
const bands: [number, number, number][] = [
[1, 6, 0.7],
[7, 16, 1.2],
[17, 45, 2.8],
[17, 45, 2.8],
[7, 16, 1.2],
[1, 6, 0.7],
];
bands.forEach(([start, end, gain], i) => {
let sum = 0;
for (let j = start; j <= end; j++) sum += data[j];
const mean = sum / Math.max(1, end - start + 1);
const target = Math.max(6, Math.min(48, (mean / 255) * 48 * gain));
const current = heightsRef.current[i];
const k = target > current ? 0.45 : 0.18;
const next = current + (target - current) * k;
heightsRef.current[i] = next;
if (bars[i]) bars[i]!.style.height = `${next.toFixed(1)}px`;
});
};
loop();
return () => cancelAnimationFrame(raf);
}, [analyserRef, playing]);
return (
<div className="flex h-[48px] items-center gap-[5px]" aria-hidden="true">
{[0, 1, 2, 3, 4, 5].map((i) => (
<div
key={i}
ref={(el) => {
barRefs.current[i] = el;
}}
className="w-[6px] rounded-full bg-[var(--text)]"
style={{ height: 6 }}
/>
))}
</div>
);
}
const MAX_OVERFLOW = 50;
function decay(value: number, max: number) {
if (max === 0) return 0;
const entry = value / max;
const sigmoid = 2 * (1 / (1 + Math.exp(-entry)) - 0.5);
return sigmoid * max;
}
function ElasticSlider({
progress,
onSeek,
}: {
progress: number;
onSeek: (pct: number) => void;
}) {
const sliderRef = useRef<HTMLDivElement>(null);
const clientX = useMotionValue(0);
const overflow = useMotionValue(0);
useMotionValueEvent(clientX, "change", (latest) => {
if (sliderRef.current) {
const { left, right } = sliderRef.current.getBoundingClientRect();
let delta = 0;
if (latest < left) delta = left - latest;
else if (latest > right) delta = latest - right;
overflow.jump(decay(delta, MAX_OVERFLOW));
}
});
const trackScaleX = useTransform(() => {
if (sliderRef.current) {
const { width } = sliderRef.current.getBoundingClientRect();
return 1 + overflow.get() / width;
}
return 1;
});
const handlePointerMove = (e: React.PointerEvent<HTMLDivElement>) => {
if (e.buttons > 0 && sliderRef.current) {
const { left, width } = sliderRef.current.getBoundingClientRect();
const pct = Math.max(0, Math.min(100, ((e.clientX - left) / width) * 100));
onSeek(pct);
clientX.jump(e.clientX);
}
};
const handlePointerUp = () => {
animate(overflow, 0, { type: "spring", bounce: 0.5 });
};
return (
<div
ref={sliderRef}
onPointerMove={handlePointerMove}
onPointerDown={(e) => {
handlePointerMove(e);
e.currentTarget.setPointerCapture(e.pointerId);
}}
onPointerUp={handlePointerUp}
className="relative flex w-full cursor-grab touch-none select-none items-center py-2"
>
<motion.div style={{ scaleX: trackScaleX }} className="h-[7px] w-full">
<div className="h-full w-full overflow-hidden rounded-full bg-[var(--hover-surface)]">
<div
className="h-full rounded-full bg-[#E7E7E2]"
style={{ width: `${progress}%` }}
/>
</div>
</motion.div>
</div>
);
}
function VerticalElasticSlider({
volume,
onChange,
}: {
volume: number;
onChange: (vol: number) => void;
}) {
const sliderRef = useRef<HTMLDivElement>(null);
const handlePointerMove = (e: React.PointerEvent<HTMLDivElement>) => {
if (e.buttons > 0 && sliderRef.current) {
const { top, height } = sliderRef.current.getBoundingClientRect();
const pct = Math.max(0, Math.min(1, 1 - (e.clientY - top) / height));
onChange(pct);
}
};
return (
<div
ref={sliderRef}
onPointerMove={handlePointerMove}
onPointerDown={(e) => {
handlePointerMove(e);
e.currentTarget.setPointerCapture(e.pointerId);
}}
className="relative flex h-full w-full cursor-grab touch-none select-none items-center justify-center"
>
<div className="h-full w-[6px] rounded-full bg-[var(--hover-surface)] overflow-hidden">
<div
className="absolute bottom-0 w-full rounded-full bg-[#E7E7E2]"
style={{ height: `${Math.round(volume * 100)}%` }}
/>
</div>
</div>
);
}
function LyricsList({
lyrics,
currentTime,
onSeekTime,
}: {
lyrics: LyricLine[];
currentTime: number;
onSeekTime: (time: number) => void;
}) {
const LINE_HEIGHT = 56;
let activeIndex = 0;
for (let i = 0; i < lyrics.length; i++) {
if (currentTime >= lyrics[i].time) activeIndex = i;
else break;
}
return (
<div
className="relative h-[168px] w-full overflow-hidden"
style={{
maskImage:
"linear-gradient(to bottom, transparent 0%, black 18%, black 82%, transparent 100%)",
WebkitMaskImage:
"linear-gradient(to bottom, transparent 0%, black 18%, black 82%, transparent 100%)",
}}
>
<motion.div
animate={{ y: -(activeIndex - 1) * LINE_HEIGHT }}
transition={{ type: "spring", stiffness: 340, damping: 28, mass: 0.6 }}
className="flex flex-col items-center w-full will-change-transform"
>
{lyrics.map((line, idx) => {
const isActive = idx === activeIndex;
const isAdjacent = Math.abs(idx - activeIndex) === 1;
return (
<div
key={idx}
onClick={() => onSeekTime(line.time)}
style={{ height: LINE_HEIGHT }}
className="flex w-full items-center justify-center px-4 text-center cursor-pointer select-none"
>
<div
className={
isActive
? "opacity-100 blur-0 text-[var(--text)] font-semibold text-[15px] transition-all duration-300"
: isAdjacent
? "opacity-35 blur-[0.4px] text-[var(--text-secondary)] hover:opacity-75 hover:blur-none transition-all duration-300"
: "opacity-0 pointer-events-none transition-all duration-300"
}
>
{line.text}
</div>
</div>
);
})}
</motion.div>
</div>
);
}
function VolumeIcon({ volume, muted }: { volume: number; muted: boolean }) {
if (muted || volume === 0) {
return (
<svg viewBox="0 0 16 16" fill="currentColor" className="h-4 w-4">
<path d="M9.741.85a.75.75 0 0 1 .375.65v13a.75.75 0 0 1-1.125.65l-6.925-4a3.64 3.64 0 0 1-1.33-4.967 3.64 3.64 0 0 1 1.33-1.332l6.925-4a.75.75 0 0 1 .75 0zm-6.924 5.3a2.14 2.14 0 0 0 0 3.7l5.8 3.35V2.8z" />
<path d="M11.5 5.5a.75.75 0 0 1 1.06 0L13.75 6.69l1.19-1.19a.75.75 0 1 1 1.06 1.06L14.81 7.75l1.19 1.19a.75.75 0 1 1-1.06 1.06l-1.19-1.19-1.19 1.19a.75.75 0 0 1-1.06-1.06l1.19-1.19-1.19-1.19a.75.75 0 0 1 0-1.06z" />
</svg>
);
}
return (
<svg viewBox="0 0 16 16" fill="currentColor" className="h-4 w-4">
<path d="M9.741.85a.75.75 0 0 1 .375.65v13a.75.75 0 0 1-1.125.65l-6.925-4a3.64 3.64 0 0 1-1.33-4.967 3.64 3.64 0 0 1 1.33-1.332l6.925-4a.75.75 0 0 1 .75 0zm-6.924 5.3a2.14 2.14 0 0 0 0 3.7l5.8 3.35V2.8zm8.683 4.29V5.56a2.75 2.75 0 0 1 0 4.88" />
<path d="M11.5 13.614a5.752 5.752 0 0 0 0-11.228v1.55a4.252 4.252 0 0 1 0 8.127z" />
</svg>
);
}
function LyricsIcon({ className }: { className?: string }) {
return (
<svg viewBox="0 0 16 16" fill="currentColor" className={className}>
<path d="M13.426 2.574a2.831 2.831 0 0 0-4.797 1.55l3.247 3.247a2.831 2.831 0 0 0 1.55-4.797M10.5 8.118l-2.619-2.62L4.74 9.075 2.065 12.12a1.287 1.287 0 0 0 1.816 1.816l3.06-2.688 3.56-3.129zM7.12 4.094a4.331 4.331 0 1 1 4.786 4.786l-3.974 3.493-3.06 2.689a2.787 2.787 0 0 1-3.933-3.933l2.676-3.045z" />
</svg>
);
}
export function MusicPlayer({ songs }: { songs: Song[] }) {
const [openIndex, setOpenIndex] = useState<number | null>(null);
const [isLyricsMode, setIsLyricsMode] = useState(false);
const [progress, setProgress] = useState(0);
const [isPlaying, setIsPlaying] = useState(false);
const [volume, setVolume] = useState(0.7);
const [isMuted, setIsMuted] = useState(false);
const [lyrics, setLyrics] = useState<LyricLine[]>([]);
const audioRef = useRef<HTMLAudioElement>(null);
const audioCtxRef = useRef<AudioContext | null>(null);
const analyserRef = useRef<AnalyserNode | null>(null);
const gainRef = useRef<GainNode | null>(null);
const displayTime = useAnimatedTime(audioRef);
const ensureAudioGraph = () => {
if (audioCtxRef.current) return;
const audio = audioRef.current;
if (!audio) return;
const ctx = new AudioContext();
const source = ctx.createMediaElementSource(audio);
const analyser = ctx.createAnalyser();
const gainNode = ctx.createGain();
analyser.fftSize = 256;
analyser.smoothingTimeConstant = 0.55;
source.connect(analyser);
analyser.connect(gainNode);
gainNode.connect(ctx.destination);
audioCtxRef.current = ctx;
analyserRef.current = analyser;
gainRef.current = gainNode;
};
const toggleSong = (index: number) => {
ensureAudioGraph();
if (audioCtxRef.current?.state === "suspended") {
audioCtxRef.current.resume();
}
const audio = audioRef.current;
if (!audio) return;
if (openIndex === index) {
if (isPlaying) {
audio.pause();
} else {
audio.play().catch(() => {});
}
return;
}
setOpenIndex(index);
audio.src = songs[index].audio;
audio.currentTime = 0;
audio.play().catch(() => {});
if (songs[index].lyric) {
fetch(songs[index].lyric)
.then((r) => r.text())
.then((txt) => setLyrics(parseLrc(txt)))
.catch(() => setLyrics([]));
} else {
setLyrics([]);
}
};
return (
<>
<audio
ref={audioRef}
onTimeUpdate={(e) => {
const d = e.currentTarget.duration;
if (d > 0) setProgress((e.currentTarget.currentTime / d) * 100);
}}
onPlay={() => setIsPlaying(true)}
onPause={() => setIsPlaying(false)}
className="hidden"
/>
<div className="space-y-3">
{songs.map((song, index) => {
const isOpen = openIndex === index;
return (
<motion.div
key={song.title}
role="button"
animate={{
height: isOpen ? 450 : 72,
borderRadius: isOpen ? 32 : 20,
}}
transition={{ type: "spring", stiffness: 420, damping: 30 }}
onClick={() => toggleSong(index)}
className="relative w-full cursor-pointer overflow-hidden bg-[var(--tooltip-surface)] select-none"
>
<AnimatePresence mode="sync">
{!isOpen ? (
<motion.div
key="collapsed"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
className="absolute inset-0 flex items-center p-3"
>
<img
src={song.image}
alt={song.title}
className="h-12 w-12 rounded-xl object-cover"
/>
<div className="ml-3 flex flex-col justify-center">
<p className="text-[13px] text-[var(--text-secondary)]">{song.artist}</p>
<h3 className="text-[15px] font-bold text-[var(--text)]">{song.title}</h3>
</div>
</motion.div>
) : (
<motion.div
key="expanded"
initial={{ opacity: 0, scale: 0.96 }}
animate={{ opacity: 1, scale: 1 }}
exit={{ opacity: 0, scale: 0.95 }}
className="absolute inset-0 flex h-full w-full flex-col items-center overflow-hidden"
>
<motion.div
animate={{
y: isLyricsMode ? -240 : 0,
opacity: isLyricsMode ? 0 : 1,
scale: isLyricsMode ? 0.75 : 1,
}}
transition={{ type: "spring", stiffness: 320, damping: 30 }}
className="pointer-events-none absolute left-1/2 top-0 w-[380px] -translate-x-1/2 -translate-y-1/2 z-10"
>
<motion.div
animate={{ rotate: 360 }}
transition={{ duration: 20, repeat: Infinity, ease: "linear" }}
className="relative aspect-square w-full rounded-full overflow-hidden"
>
<img
src={song.image}
alt={song.title}
className="absolute inset-0 h-full w-full object-cover"
/>
<div
className="absolute inset-0"
style={{
backgroundImage:
"repeating-radial-gradient(circle, transparent 0 4px, rgba(0,0,0,0.12) 4px 4.5px)",
}}
/>
<div className="absolute left-1/2 top-1/2 h-[18%] w-[18%] -translate-x-1/2 -translate-y-1/2 rounded-full bg-[#1c1c1f]">
<div className="absolute left-1/2 top-1/2 h-[8%] w-[8%] -translate-x-1/2 -translate-y-1/2 rounded-full bg-black" />
</div>
</motion.div>
</motion.div>
<motion.div
animate={{ marginTop: isLyricsMode ? 16 : 220 }}
transition={{ type: "spring", stiffness: 320, damping: 30 }}
className="scale-[0.8] origin-center z-20 flex-shrink-0"
>
<Equalizer playing={isPlaying} analyserRef={analyserRef} />
</motion.div>
<div className="mt-4 flex flex-col items-center text-center z-20 flex-shrink-0">
<p className="text-[16px] text-[var(--text-secondary)]">{song.artist}</p>
<h3 className="text-[22px] font-bold text-[var(--text)]">{song.title}</h3>
</div>
<div className="relative flex-1 z-20 flex w-full items-center justify-center min-h-0">
<motion.div
animate={{
opacity: isLyricsMode ? 1 : 0,
scale: isLyricsMode ? 1 : 0.96,
}}
transition={{ type: "spring", stiffness: 320, damping: 30 }}
style={{ pointerEvents: isLyricsMode ? "auto" : "none" }}
className="w-full px-4"
>
<LyricsList
lyrics={lyrics}
currentTime={displayTime}
onSeekTime={(time) => {
if (audioRef.current) audioRef.current.currentTime = time;
}}
/>
</motion.div>
</div>
<div className="w-[220px] z-20 flex-shrink-0">
<ElasticSlider
progress={progress}
onSeek={(pct) => {
const audio = audioRef.current;
if (audio && audio.duration) {
audio.currentTime = (pct / 100) * audio.duration;
}
}}
/>
</div>
<div className="mt-1 mb-[52px] flex items-center justify-center gap-1 text-[16px] tabular-nums text-[var(--text-secondary)] z-20 flex-shrink-0">
<span className="text-[var(--text)]">
<RollingTime value={displayTime} />
</span>
<span>/</span>
<span>{formatTime(song.duration)}</span>
</div>
<div
className="absolute bottom-4 left-6 z-30 flex items-center"
onClick={(e) => e.stopPropagation()}
>
<span className="lyrics-toggle relative flex items-center justify-center">
<button
type="button"
onClick={() => setIsLyricsMode((prev) => !prev)}
className="flex h-7 w-7 items-center justify-center transition-transform active:scale-90 cursor-pointer outline-none"
aria-label={isLyricsMode ? "Close" : "Lyrics"}
>
<LyricsIcon
className={
isLyricsMode
? "h-[18px] w-[18px] text-[var(--text)] transition-colors duration-200"
: "h-[18px] w-[18px] text-[var(--text-secondary)] hover:text-[var(--text)] opacity-40 hover:opacity-100 transition-colors duration-200"
}
/>
</button>
<span className="tooltip-bubble" role="tooltip">
{isLyricsMode ? "Close" : "Lyrics"}
</span>
</span>
</div>
<div
className="absolute bottom-4 right-6 z-30 flex flex-col items-center gap-1.5"
onClick={(e) => e.stopPropagation()}
>
<div className="h-16 w-5 flex items-center justify-center">
<VerticalElasticSlider
volume={isMuted ? 0 : volume}
onChange={(v) => {
setVolume(v);
setIsMuted(false);
if (audioRef.current) audioRef.current.volume = v;
}}
/>
</div>
<button
type="button"
onClick={() => {
const nextMuted = !isMuted;
setIsMuted(nextMuted);
if (audioRef.current) audioRef.current.volume = nextMuted ? 0 : volume;
}}
className="flex h-6 w-6 items-center justify-center text-[var(--text-secondary)] transition-colors hover:text-[var(--text)]"
>
<VolumeIcon volume={volume} muted={isMuted} />
</button>
</div>
</motion.div>
)}
</AnimatePresence>
</motion.div>
);
})}
</div>
</>
);
}3. Page Implementation
app/music/page.tsximport { MusicPlayer } from "../components/music-player";
import { SONGS } from "../music-data";
export default function MusicPage() {
return (
<main className="mx-auto max-w-xl px-6 py-20">
<h1 className="text-2xl font-bold text-[var(--text)] mb-6">Music Player</h1>
<MusicPlayer songs={SONGS} />
</main>
);
}Summary
| Feature | Library | Key Concept |
|---|---|---|
| Expand/Collapse | Framer Motion | Spring animation, AnimatePresence |
| Vinyl Record | CSS | Repeating radial gradient, rotate animation |
| Equalizer | Web Audio API | AnalyserNode, frequency data |
| Lyrics Sync | Framer Motion | Spring scroll, opacity blur |
| Elastic Slider | Framer Motion | Motion values, decay function |
| Rolling Timer | CSS Transform | translateY strip animation |
Happy coding!