Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Audio Player

ProNew

A music player on a real audio element: cover, scrubber with buffering, volume, speed, shuffle, repeat and a playlist, in four layouts.

Installation

pnpm dlx shadcn@latest add @viewport/audio-player

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above comes with Truffle Pro.

Props

PropTypeDefault
tracks*AudioTrack[]

The playlist. One track makes a single-track player.

—
layout"card" | "stacked" | "bar" | "mini"

`card` puts the cover beside the controls and stacks them when narrow, `stacked` is a centred column with a large cover, `bar` is a slim strip for the bottom of a page, and `mini` is a small card for a corner.

"card"
playlistboolean

Show the track list. Defaults to on when there is more than one track.

—
defaultPlaylistOpenboolean

Whether the track list starts open.

true
defaultIndexnumber

Track selected at first.

0
defaultVolumenumber

Volume at first, from 0 to 1.

1
speedsnumber[]

Playback rates the speed button steps through. An empty list hides it.

[1, 1.25, 1.5, 2, 0.75]
modesboolean

Show the shuffle and repeat buttons.

true
volumeboolean

Show the volume control.

true
loadingboolean

Draws a placeholder while the track list is being fetched.

false
disabledboolean

Turns every control off.

false
labelstring

Accessible name of the player.

"Audio player"
onTrackChange(index: number, track: AudioTrack) => void

Called when another track is selected.

—
onPlayingChange(playing: boolean) => void

Called when sound starts or stops.

—
classNamestring—

Accessibility

  • Every control is a native button or range input with a name; the play and mute buttons rename themselves (Play or Pause, Mute or Unmute), and shuffle and the playlist toggle report their state.
  • The scrubber is a slider: Left and Right move 5 seconds, Page Up and Page Down 30, Home and End jump to the ends, and it reads as “1 minute 5 seconds of 3 minutes”.
  • The current track is marked in the list, a track change is announced politely, and a file that fails to load raises an alert with a Retry button.
  • Under reduced motion the equalizer, the buffering spinner and the playlist slide stand still, and progress updates in steps.