Reference
Audio
Audio player. transcript links what was said, which is what a reader who cannot hear it needs.
Audio(src: String, controls: Bool, autoplay: Bool, …)
Before 5.0
controls
autoplay
loop
No preview for this one: the example below shows how it is written.
Example
Stack(gap: .sm) {
Heading("Episode 12: Shipping 7.0").h3
Text("Forty minutes on types, results and what changed.").muted
Audio(src: "/media/episode-12.mp3", transcript: "/media/episode-12.txt").controls
}
Background music that loops
Audio(src: "/media/ambient.mp3", transcript: "/media/ambient.txt").controls.loop
Props
| Prop | Type | Unset | Meaning |
|---|---|---|---|
src: | String | none | The audio's address |
controls: | Bool | false | The browser's playback controls; without them the player shows nothing. Written as a flag, |
autoplay: | Bool | false | Start playing when shown; most browsers refuse until the reader has interacted with the page. Written as a flag, |
loop: | Bool | false | Start again when it ends. Written as a flag, |
transcript: | String | none | The address of what was said, linked as |
Attribute families: global, aria, data. Plus the 22 universal props every element takes: animate:, exit:, speed:, duration:, delay:, easing:, stagger:, on:, count:, shared:, class:, ref:, drag:, dragGroup:, dropValue:, dropAxis:, dropInside:, roving:, trapFocus:, mount:, update:, cleanup:.
Flags and cases
A flag is written after the parentheses with a dot: a Bool prop, or a case of one of the element's enum props. A case the enum lacks is an error with a hint.
.controls
.autoplay
.loop
Events
The DOM events it is drawn to answer. Any other DOM event works too, in an on … { } handler.
| Event | Sends | Meaning |
|---|---|---|
on play | DOM | A video or audio started playing |
on pause | DOM | A video or audio paused |
on ended | DOM | A video or audio reached its end |
on timeupdate | DOM | A playing video or audio moved on |
Every element also takes the props, the events and the attribute families listed on every element.
Slots
It takes no slots.
Renders with the class wf-audio, stable across releases, so a stylesheet may target it.
Codes this can raise
These controls list the props' cases; the example below shows them written.