Now Playing
An interactive music player card with a spinning, scrubbable vinyl disc and real-time level meters.
Now Playing
An interactive music player card with a spinning, scrubbable vinyl disc and real-time level meters.
The card behaves like a small turntable. The disc spins at cruise speed while playing, a finger or mouse can hold and spin it to scrub through the track, and the level meters react to the speed of the spin. Time rolls digit by digit, and the tonearm lifts and drops with playback.
Installation
Install the component with the Craft-UI Blocks CLI — it drops now-playing.tsx into your project and wires up its runtime dependencies:
npx mvpblocks add now-playingpnpm dlx mvpblocks add now-playingyarn dlx mvpblocks add now-playingbunx mvpblocks add now-playingFile Structure
The CLI saves the component to your project's components/ui folder:
Import the default export from @/components/ui/now-playing. The prop type is exported as NowPlayingProps, and the track shape as NowPlayingTrack.
Usage
NowPlaying is a client component and every prop is optional — with no props it renders three demo tracks. Drop it into any card slot:
"use client";
import NowPlaying from "@/components/ui/now-playing";
export function MusicCard() {
return <NowPlaying />;
}Pass your own tracks with title, artist, duration in seconds, and an optional artwork variant of 0, 1, or 2. The player starts on defaultTrack and can begin paused:
const tracks = [
{
title: "Midnight Drive",
artist: "Electric Dreams",
duration: 245,
artwork: 0,
},
{
title: "Ocean Waves",
artist: "Nature Sounds",
duration: 180,
artwork: 1,
},
];
<NowPlaying
tracks={tracks}
defaultTrack={0}
autoPlay={false}
accent="#3b82f6"
onTrackChange={(index) => console.log("track", index)}
/>Enable the optional glass treatment when you want the inset shadow and SVG refraction. It is off by default and the refraction is Chromium-only:
<NowPlaying glassEffect className="max-w-md" />Theming
The frame uses zinc tones: rounded-3xl border-zinc-200 bg-white in light mode, inverting to dark:border-zinc-800 dark:bg-zinc-900. Text is zinc-based, the meter bars are bg-(--now-playing-accent), and the accent is written as a CSS custom property on the root element.
The default accent is #f97316. Change it with accent, which updates the meter, the progress fill, and the printed label art at once:
<NowPlaying accent="#10b981" />glassEffect adds translucent background layers, inset highlights, and a feDisplacementMap filter. Browsers without backdrop-filter: url() support simply show the regular card.
Animations
- Cruise: at steady 33 1/3 rpm the disc rotation hands off to WAAPI, so it keeps turning on the compositor at 200 degrees per second.
- Spin up / down: speed relaxes toward cruise or zero with time constants of
0.22sand0.2s; a flick coasts back to cruise over0.45s. - Scrubbing: holding the disc stops it within about
50ms, and pointer angle maps one-to-one to track time until a faster spin adds up to 6x speed. - Level meters: five bars attack in
80msand decay in300ms, following a deterministic noise function of track time. - Rolling time: each digit rolls over in
220ms, keyed from the right so the seconds stay stable when minutes gain a digit. - Reduced motion: cruise animation is cancelled, the meter becomes a still frame, and changes appear instantly.
How it works
One requestAnimationFrame loop integrates disc angle, track time, meter envelope, and the readout whenever the player is awake. It sleeps once everything settles, pauses when the card leaves the viewport or the tab is hidden, and only calls React state when the displayed second actually changes.
While playing at cruise, startCruise pins the current angle inline and starts an infinite compositor animation. Any interaction stops that animation, reads the angle back, and returns control to the simulation so the disc never visually jumps.
Scrubbing measures pointer angle around the disc center, unwraps the ±180° seam, and smooths release velocity over an 80ms window. The scrubber rail uses the same time value and stretches past either end with rubber-band damping. Arrow keys move by five seconds, Home goes to the start, and End jumps near the finish.
Props
Prop
Type
NowPlayingTrack
Prop
Type
Registry Bundle
Install the exact registry entry shown on the right when you want the component file and its declared runtime dependencies together. Dependencies: lucide-react (transport and control icons) and class-variance-authority (the glass variants).
Contact
If you find any bug or issue, feel free to raise an issue.
Last updated on