Dojo NG is being built in the open, one section at a time — follow along on Heptapod.

API REFERENCE · MEDIA

<dj-audio>

A themed audio player.

It wraps the native HTMLAudioElement, hidden in the shadow root, with Dojo NG controls: a play/pause button, a seek slider, and a readout of the current and total time. It needs no third-party player.

Try it in the playground

@dojo-ng/audio · v0.1.2

npm install @dojo-ng/audio

import "@dojo-ng/audio";

Accessibility

  • Give the player a label. It becomes the accessible name.
  • Keyboard support comes from the button and the slider.

Playback state

  • The play/pause button follows the media's real play and pause events, not the click. It stays correct when you control playback through media().
  • The seek slider's maximum comes from the media duration, and its value follows playback.

Events and analytics

  • dj-time fires at most once per second.
  • Put analytics, xAPI statements, and saved resume positions in your own event listeners, not in the component.
  • media() returns the raw audio element for advanced use. Code that uses it is not supported.

Properties

PropertyAttributeTypeDefault
srcMedia source URL. src string None
labelAccessible name for the player. label string None
preloadNative preload hint. preload string "metadata"

Events

dj-playdj-pausedj-endeddj-time

CSS parts

Style these with dj-audio::part(name).

PartDescription
barthe control row
playthe play/pause button
seekthe slider
time

Methods

MethodDescription
play()Start playback.
pause()Pause playback.
media(): HTMLAudioElement | nullThe underlying HTMLAudioElement. Advanced escape hatch; no support implied.