Audio player
A recording with its own controls over a real <audio>: play, scrubber
(optionally over a waveform), times, skips, speed, mute and volume, download,
and a transcript that follows along. dsAudio drives it.
Anatomy
▁▃▅▇▅▃▁▂▄▆▄▂▁▃▅▇▅▃▁▂▄▆▄▂▁▃ ← scrubber: a native range over the bars, --ds-audio-at lights the played part
0:42 −3:18 ← elapsed, remaining
[1×] [↺10] [ ▶ ] [10↻] [🔊 ───] [⤓]
──────────────────────────────
0:00 Maya Hi, it is Maya. ← cues: ol, the current one aria-current
0:04 About Thursday.
Compact is one row: play, the scrubber, the time, speed, download.
| Part | Token | Why |
|---|---|---|
| Play | surface-inverse / on-inverse, size-11 (full) | The one control that matters, heaviest. |
| Other controls | text-fg-muted, hover:bg-fg/10, rounded-full | |
| Bars | fg/15, played fg | The played part is the same bars clipped by clip-path: inset() from --ds-audio-at, one custom property per frame, no layout. RTL clips from the other side. |
| Track (no waveform) | fg/15, fill fg, clipped the same way | |
| Times | text-meta tabular-nums text-fg-muted; remaining with a true minus (U+2212) | Digits that do not jitter. |
| Current cue | accent-tint + text-fg |
Without the script
The <audio controls> is the player: the custom UI is hidden until the
script marks the root data-ds-ready, then the native one is hidden and its
controls removed. Cues render as text with a static time; their play
buttons appear only when ready.
Behaviour
- One at a time: a module-level set of playing players;
playpauses the others unless either isindependent. - Scrubber:
maxthe duration (durationprop until the file's own),valuethe time, not overwritten while held.aria-valuetext"1 minute 12 seconds of 4 minutes", rendered in PHP and kept by the script, changed once a second (the PHP and JSspoken/clockmirror each other). - Speed: a button stepping through
speeds, showing "1.5×", with a visually hidden "Playback speed" before it. A select was the alternative: a button is one press for the common case (faster) and fits compact. - Volume:
pointer-coarse:hiddenwith mute; on iOS a page cannot set it. - Cues:
[data-ds-audio-cue]withdata-start/data-endanywhere in the root (the prop's list or thetranscriptslot). The current one getsaria-current="true"and is scrolled into view in its list; a press on one seeks and plays (not when text is being selected). - Events from the root, bubbling:
play,pause,ended,timeupdate(at most once a second), each{ currentTime, duration }. - Media Session:
titleandartiston play, where supported. - Error: the message in a
role=statusparagraph.
Accessibility
- Role and name:
role=groupnamed bytitleorlabel. - Play: one button, its name Play / Pause. Mute:
aria-pressed. - Keyboard:
| Key | Does |
|---|---|
| Space | Play / pause, anywhere in the player but a button, link or field (the scrubber included) |
| Left / Down, Right / Up | −5 s / +5 s on the scrubber |
| Page Down / Page Up | −30 s / +30 s |
| Home / End | Start / end |
- Focus: each control rings itself; the scrubber's and volume's rings are
on their wrappers (
has-focus-visible:), the inputs being transparent or native. - Motion: nothing moves but the light on the bars, which is the content.
Do not
- Autoplay, or start a player from anything but a press.
- Announce the time continuously. The valuetext changes once a second and is read when the slider is focused; there is no live region for it.
- Decode the file in the browser for a waveform. Peaks come from the host.
From the package repo: edit this page on GitHub.