Cassette player Pro
One payment, every Pro piece. $9 tomorrow.
Install
npx shadcn@latest add @mu-pro/cassette-playerPro. Installs with your licence key through the @mu-pro registry; the key comes with Pro. Lands in components/mu/cassette-player/ with the shared foundation.
Usage
import { CassettePlayer } from "@/components/mu/cassette-player/CassettePlayer";
<CassettePlayer
tracks={[
{ title: "Opening", artist: "Your Band", duration: 201, cover: "/covers/opening.webp", src: ["/audio/opening.m4a", "/audio/opening.mp3"] },
{ title: "Night drive", artist: "Your Band", duration: 232, src: "/audio/night-drive.mp3" },
]}
/>
// controlled: the player asks to play and you decide; it moves `track` itself (the keys, a track's end,
// a wind crossing into the next) and tells you, so keep what it tells you
const [playing, setPlaying] = useState(false);
const [track, setTrack] = useState(0);
<CassettePlayer tracks={tracks} playing={playing} onPlayingChange={setPlaying} track={track} onTrackChange={setTrack} />Use with an agent Beta
npx shadcn@latest add @mu-pro/uisdk/cassette-playerOptional. An AI agent in your app can read and set this piece by name, and you can ask before anything it can’t undo. The piece itself doesn’t change; installs with your Pro key, like the piece. Built on UI SDK 0.1.0-beta.23, which is in beta too, so this add-on follows its releases.
Source
How it works
Building with an agent? Hand it a ready prompt for this piece.
Input and reduced motion
- Pointer / touch: the four keys on the lid (previous, play/pause, next, stop: machined 44px keys in milled pockets; play stays latched in while it plays). Drag across the window, over the reels, to scrub: its width is the whole track, the reels wind under your hand and the music holds from the first movement until you let go (a tap or a page scroll never cuts it). Drag the wheel on the top edge sideways (or up and down), or scroll on it, to turn the volume.
- Keyboard: the keys are buttons in tab order. The window is a slider: arrows step 5 seconds, Page Up and Down 30, Home and End go to the ends. The wheel is a slider too: arrows step 5%, Page Up and Down 20%, Home and End are silent and full. Space plays and pauses from either slider.
- Screen readers: the track's title and artist are a polite status; the window says the time as "1:24 of 3:52", and the wheel the volume as a percentage.
- Reduced motion: the reels don't turn, winds and title swaps are instant, and the music starts and stops at full speed; the packs, the times and the titles land where they would, and a drag still scrubs.
Props
| Prop | Default | What it does |
|---|---|---|
tracks | four demo tracks | { title, artist, duration, cover?, src? }[] | the tape; [] is an empty state (no tape: "No tracks", the keys disabled, data-empty). A new list keeps the place in range, zeroes the time and loads the new file. duration (seconds) lays each track on it, so the packs show where you are on the whole tape; src is a URL or a list in order of preference (["/a.m4a", "/a.mp3"]): the first this browser says it can play is used, and the next is tried if it fails. Without src a track keeps time silently. cover goes to the system's media controls |
playing, defaultPlaying, onPlayingChange | false | — | play state, controlled or not. A browser lets audio start only after a press: a playing set without one goes back to false through onPlayingChange |
track, defaultTrack, onTrackChange | 0 | an index | the track on show. Setting track winds the tape there; the player reports every change of its own (the keys, the end of a track, a wind crossing into another) through onTrackChange |
time, defaultTime, onTimeChange | 0 | seconds | the playhead in the track on show. Setting time glides there; onTimeChange is called 4× a second (250ms) while it plays, and on every seek. A time within 0.5s of the playhead is taken as your echo, not a seek |
volume, defaultVolume, onVolumeChange | 0.8 | 0–1 | the wheel on the top edge, in steps of 0.01; its engraved index travels with the level |
onTrackEnd | — | (index) => void | a track reached its end on its own (not by a key) |
onTrackError | — | (index) => void | every source of a track failed to load or play |
onMedia | — | (audio: HTMLAudioElement \ | null) => void | the <audio> element, once the first press makes it: route it into the equaliser or a visualiser; null when the player unmounts |
preservesPitch | false | — | the music follows the motor by default (it wows up on play and winds down on pause, pitch bent, as on tape); true keeps it at full speed and pitch, for speech |
loop | false | — | at the end of the tape, rewind and play on (otherwise it rewinds and stops) |
labels | English | — | CassettePlayerLabels: { play, pause, previous, next, stop, seek, volume, of, error, empty }: the keys' and sliders' accessible names, the word in "1:24 of 3:52", the line shown when a track can't be played ("Can't play this track") and with no tape |
sound | off | true or 0–1 | key, motor and wind sounds (see Sound) |
className | — | — | added to the root |
Sound
None. It loads in silence.
Off unless you pass sound (true, or a volume 0–1). Play spins the motor up, pause runs it down, next, previous and stop click, and a wind whirrs for as long as the tape winds (lower going back). A track ending on its own is silent, and the whirr stops if the player leaves the view. These are the player's own key sounds; the music is your src. They never play on hover, on mount or from a prop change. setMuted(true) from components/mu/sounds.ts silences every cottoncandy item at once.
Licence
Included with Pro: use it in unlimited end products for you and your clients; no reselling as a kit. See the licence.
Press play and the reels spin up behind smoked glass and wind the tape across as your track plays; drag the reels to scrub, and next winds them fast to the following song.
For playlists, mixtapes and audio previewsMore in Audio & media