@molecule/app-audio-player-svelte
v1.1.0
Published
HTML5 audio player chrome — play/pause, scrub, time, mute toggle, optional visualizer slot
Readme
@molecule/app-audio-player-svelte
Svelte HTML5 audio player chrome — play/pause, scrub bar, elapsed/total
time, and a mute toggle, over a hidden <audio> element. Use for podcasts,
voice notes, music previews, narrated lessons.
Exports <AudioPlayer> — the Svelte counterpart of
@molecule/app-audio-player-react: the same props (React names) and the
same DOM for the same input.
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Quick Start
<script lang="ts">
import { AudioPlayer } from '@molecule/app-audio-player-svelte'
</script>
<AudioPlayer
src="/audio/episode-42.mp3"
title="Episode 42: Getting Started"
subtitle="The Molecule Podcast"
onPlay={() => console.log('playing')}
onEnded={() => console.log('finished')}
/>Type
feature
Installation
npm install @molecule/app-audio-player-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelteAPI
Interfaces
AudioPlayerProps
Props accepted by the {@link AudioPlayer} component.
interface AudioPlayerProps {
/** Audio source URL (a file, a stream or a data URI). */
src: string
/** Optional title / track name. */
title?: AudioPlayerNodeProp
/** Optional artist / source label. */
subtitle?: AudioPlayerNodeProp
/** Optional waveform / visualizer slot rendered above the controls. */
visualizer?: AudioPlayerNodeProp
/**
* WebVTT captions file URL. When set, the player loads it on the media
* element's captions `<track>` and shows the current caption under the
* controls, in a polite live region that screen readers announce. Without
* it the track is empty and no caption line is shown.
*/
captions?: string
/** BCP 47 language of the captions (the track's `srclang`). */
captionsLang?: string
/**
* Human-readable name of the captions track. Defaults through i18n
* (`audio.captions`, English "Captions").
*/
captionsLabel?: string
/** Initial muted state. */
defaultMuted?: boolean
/** Autoplay (browser may block). Passed to the `<audio>` element. */
autoPlay?: boolean
/** Called when the media starts playing. */
onPlay?: () => void
/** Called when the media is paused. */
onPause?: () => void
/** Called when the media reaches its end. */
onEnded?: () => void
/** Extra classes on the outer wrapper. */
className?: string
}Constants
AudioPlayer
const AudioPlayer: LegacyComponentTypeInjection Notes
Requirements
Peer dependencies:
@molecule/app-svelte^3.5.0@molecule/app-ui^1.0.1@molecule/app-ui-svelte^1.1.0svelte^5.0.0
Runtime Dependencies
@molecule/app-svelte@molecule/app-ui@molecule/app-ui-sveltesvelte
There is NO volume slider — only a mute toggle; and no playback-rate
or skip controls. The optional visualizer prop is a free-form node
slot rendered above the controls (bring your own waveform). autoPlay is
passed to the <audio> element and is routinely blocked by browsers until
user interaction — never rely on it. Duration renders 0:00 until
loadedmetadata fires (preload="metadata"). Translations come from the
companion @molecule/app-locales-audio-player locale bond. Node-valued
props take a Svelte snippet (or a plain value).
Translations
Translation strings are provided by @molecule/app-locales-audio-player.
