Audio player

A recording with its own controls: a voice note, a call, a podcast clip. Play, a scrubber (over a waveform if you have one), the time, speed, and a transcript that follows along.

Audio player

Needs Alpine and the package's script for its own controls. Without them it is the browser's audio player, and a transcript is plain text. See getting started.

Use it

<x-ds::audio-player
    :src="$note->url"
    :title="$note->title"
    :artist="$note->author->name"
    :duration="$note->seconds"
    :waveform="$note->peaks"
    :download="true"
/>

Props

PropTypeDefaultWhat it does
srcstring—The recording. Or sources.
sourcesarray[]Rows of src and type; the browser plays the first it can.
tracksarray[]Rows of src, kind, srclang, label, default: passed through as <track>.
titlestring—Names the player, and goes to the system's media controls.
artiststring—For the system's media controls.
labelstringRecordingNames the player when there is no title.
durationnumber—Seconds, if you know them: shown before the file has loaded.
waveformarray—Peaks, one per bar, on any scale: drawn as bars that light as it plays. Compute them once on the server (for example with audiowaveform or ffmpeg).
cuesarray[]Rows of start, end (seconds), text and optionally speaker: a transcript that follows along.
variantfull compactfullCompact is one row, for a chat bubble.
speedsarray[0.75, 1, 1.25, 1.5, 2]What the speed button steps through.
downloadbool or stringfalseA download link: true for src, or a URL.
independentboolfalsePlays alongside others instead of pausing them.
preloadnone metadata autometadataPassed to the audio element.

Instead of cues, a transcript slot takes your own markup; mark each line data-ds-audio-cue with data-start and data-end and it follows along too.

How it behaves

  • One at a time. Starting a player pauses any other that is playing, unless one of them is independent.
  • The transcript marks the line being spoken and keeps it in view. Each line's time is a button that plays from there.
  • Events: play, pause and ended, and timeupdate at most once a second, with { currentTime, duration }, so a host can save where the reader got to.

Accessibility

  • A named group. Play is one button whose name changes, Play and Pause.
  • The scrubber is a native slider named "Seek", whose value is said in words: "1 minute 12 seconds of 4 minutes". The words change once a second, not on every frame.
  • Speed says its value ("Playback speed 1.5×"); Mute is a toggle with aria-pressed. Volume is left out on touch screens, where the device's buttons do it.
  • An error is said in a status region.
KeyDoes
SpacePlay or pause, from anywhere in the player but a button, link or field
Left / Right, Down / Up (on the scrubber)Back / forward 5 seconds
Page Down / Page Up (on the scrubber)Back / forward 30 seconds
Home / End (on the scrubber)The start / the end

Don't

  • Don't autoplay. Nothing starts it but a press.
  • Don't compute the waveform in the browser. Decoding the whole file to draw bars is the cost the server pays once.
  • Don't leave out a transcript for speech that matters: it is the only way some readers get it.

More in specs/audio-player.md.


From the package repo: edit this page on GitHub.

Was this page helpful?