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.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
src | string | — | The audio file, played by an <audio> of the player's own. Ignored while an <audio> is slotted. |
label | string | — | Names the player and its play button ("Play voice note from Ana"). |
peaks | number[] | undefined | undefined | The waveform: numbers from 0 to 1. Without it, the player computes it from src when it can fetch the file. |
bars | number | 48 | The most bars the waveform draws; a narrow waveform draws as many as fit. |
duration | number | undefined | undefined | The length in seconds, shown before the audio's metadata has loaded. |
exclusive | boolean | false | Pauses every other exclusive player on the page when this one starts. |
transcript | string | — | A text transcript, shown below the player behind a toggle. The transcript slot takes richer content. |
variant | AudioPlayerVariant | default | bubble is the compact chat-message look. |
preload | 'none' | 'metadata' | 'auto' | metadata | How much of the player's own <audio> loads up front, as on <audio>. none also waits for a play to compute the waveform. |
Slots
| Name | Description |
|---|---|
(default) | An <audio> to play instead of src. |
avatar | Shown before the play button: the sender of a voice message. |
transcript | The transcript, shown below the player when opened (a c2-transcript given this player's media, or text). |
Events
| Name | Type | Description |
|---|---|---|
play | The audio started playing. | |
pause | The audio paused. | |
ended | The audio played to its end. | |
ratechange | The speed changed. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
player | The row that holds the controls. |
play | The play and pause button. |
waveform | The waveform, which is the seek bar. |
time | The time. |
speed | The speed button. |
transcript | The transcript box. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-audio-player--width | length | 100% | The player's width. |
--c2-audio-player--background-color | color | #ffffff | The player's background. |
--c2-audio-player--border | border | 1px solid #e4e4e7 | The player's border. |
--c2-audio-player--border-radius | pixel | 8px | The player's corners. |
--c2-audio-player--padding | length | 10px 12px | Space inside the player. |
--c2-audio-player--gap | pixel | 12px | Space between the play button, the waveform, the time and the speed. |
--c2-audio-player--color | color | #18181b | The text colour. |
--c2-audio-player--disabled-opacity | number | 0.38 | The opacity of a player that cannot play. |
--c2-audio-player__play--size | pixel | 36px | The play button's size. |
--c2-audio-player__play--background-color | color | rgb(2, 101, 220) | The play button's fill. |
--c2-audio-player__play--color | color | #ffffff | The play and pause icon. |
--c2-audio-player__waveform--height | pixel | 32px | The waveform's height. |
--c2-audio-player__bar--width | pixel | 3px | The width of a bar. |
--c2-audio-player__bar--gap | pixel | 2px | The space between bars. |
--c2-audio-player__bar--color | color | #d4d4d8 | A bar not played yet. |
--c2-audio-player__bar__played--color | color | rgb(2, 101, 220) | A played bar. |
--c2-audio-player__time--color | color | #71717a | The time. |
--c2-audio-player__time--font-size | pixel | 12px | The time's size. |
--c2-audio-player__speed--background-color | color | #f4f4f5 | The speed button's fill. |
--c2-audio-player__speed--color | color | #18181b | The speed button's text. |
--c2-audio-player__speed--font-size | pixel | 12px | The speed button's text size. |
--c2-audio-player__toggle--color | color | rgb(2, 101, 220) | The transcript toggle. |
--c2-audio-player__transcript--background-color | color | #f4f4f5 | The transcript box. |
--c2-audio-player__transcript--font-size | pixel | 13px | The transcript's text size. |
--c2-audio-player__error--color | color | #dc2626 | The message shown when the audio cannot play. |
--c2-audio-player__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | The focus ring. |
--c2-audio-player__bubble--background-color | color | #ffffff | The bubble variant's fill. |
--c2-audio-player__bubble--border-radius | length | 16px 16px 16px 4px | The bubble variant's corners. |
--c2-audio-player__bubble--box-shadow | shadow | 0 1px 2px rgba(24, 24, 27, 0.08) | The bubble variant's shadow. |
--c2-audio-player__bubble--max-width | length | 320px | The bubble variant's widest. |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under audio-player, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
play | Play | — |
pause | Pause | — |
playLabel | Play {0} | {0} label |
pauseLabel | Pause {0} | {0} label |
player | Audio | — |
seek | Seek | — |
position | {0} of {1} | {0} time {1} duration |
speed | Playback speed {0} | {0} speed |
showTranscript | Show transcript | — |
hideTranscript | Hide transcript | — |
error | Cannot play this recording | — |