Audio Player
Waveform playback for voice notes and recordings: the waveform is the seek bar, with the time, a speed toggle and an optional transcript.
c2-audio-player plays a voice note or a recording the way Slack clips and WhatsApp voice messages do: a play button, the waveform as the seek bar, the time and a speed toggle. It plays src with an <audio> of its own, or an <audio> you put inside it (with its <source>s), which it never writes on. media is that element either way, to hand to c2-transcript or c2-audio-visualizer.
Import
import '@c2n/components/audio-player'Usage
Hi team, quick update on the launch. The build is green and QA signed off this morning, so we can ship on Thursday as planned.
Waveform
peaks is the waveform: numbers from 0 to 1, usually computed once when the recording is saved and stored with it. The player brings them to bars bars (48 by default), or fewer when the waveform is narrower than that many bars at the bar width and gap. Without peaks, the player fetches the file once and decodes it with Web Audio to compute them, which only works for a file it may read (same-origin, or served with CORS); otherwise the bars stay flat. preload="none" delays that, and any loading, until the first play.
duration (in seconds) shows the length before the audio’s metadata has loaded, so a conversation full of voice notes shows every length without fetching every file.
Playback
The waveform is the seek bar: click or drag it, or focus it and use the arrow keys (5 seconds), Home and End; Space plays and pauses. The played bars take the accent colour. The speed button cycles 1×, 1.5× and 2×. exclusive pauses any other exclusive player on the page when this one starts, as a chat does. play() and pause() drive it from script, and the host fires play, pause, ended and ratechange.
Transcript and layouts
transcript (text), or richer content in the transcript slot (a c2-transcript given this player’s media), adds a toggle that opens the transcript below the player. variant="bubble" is the compact chat look: the time and speed under the waveform, at most --c2-audio-player__bubble--max-width wide, with the avatar slot before the play button.
Accessibility
The player is a group named by label, and the play button says what it does (“Play voice note from Ana”, “Pause voice note from Ana”). The waveform is a slider read as “0:12 of 0:47”; the speed and the transcript toggle are buttons, the toggle with its expanded state. A file that cannot play says so in place of the time: the play and speed buttons are disabled, and the waveform is marked disabled and leaves the tab order.