@molecule/app-audio-player-react
Feature · audio-player · App (browser) · v4.2.1 · Apache-2.0
Audio player for React DOM and React Native with play, pause, seek, mute, and captions.
npm install @molecule/app-audio-player-reactHow it works
@molecule/app-audio-player-react is a ready-made audio-player feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.
import { AudioPlayer } from '@molecule/app-audio-player-react'
;<AudioPlayer
src="/audio/episode-42.mp3"
title="Episode 42: Getting Started"
subtitle="The Molecule Podcast"
onPlay={() => console.log('playing')}
onEnded={() => console.log('finished')}
/>Works with: @molecule/app-audio, @molecule/app-logger, @molecule/app-react, @molecule/app-ui, @molecule/app-ui-react, @molecule/app-utilities
Reference
Audio player for React DOM and React Native with play, pause, seek, elapsed/total time, mute, and optional WebVTT captions.
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
import { AudioPlayer } from '@molecule/app-audio-player-react'
;<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-react @molecule/app-audio @molecule/app-logger @molecule/app-react @molecule/app-ui @molecule/app-ui-react @molecule/app-utilities react
npm install -D @types/react
API
Interfaces
AudioPlayerProps
Props for AudioPlayer.
interface AudioPlayerProps {
src: string
/** Optional title / track name. */
title?: ReactNode
/** Optional artist / source label. */
subtitle?: ReactNode
/** Optional waveform / visualizer slot rendered above the controls. */
visualizer?: ReactNode
/**
* WebVTT captions file URL. The current caption appears in a polite live
* region below the controls.
*/
captions?: string
/** BCP 47 language for the captions track and its visible caption text. */
captionsLang?: string
/**
* Human-readable name of the browser's captions track. Defaults through i18n
* (`audio.captions`, English "Captions").
*/
captionsLabel?: string
/** Initial muted state. */
defaultMuted?: boolean
/** Autoplay (browser may block). */
autoPlay?: boolean
/** Callbacks. */
onPlay?: () => void
onPause?: () => void
onEnded?: () => void
/** Extra classes. */
className?: string
}
Functions
AudioPlayer(props)
HTML5 audio player chrome — play/pause, scrub, time, mute, optional visualizer slot. Use for podcasts, voice notes, music previews, narrated lessons.
function AudioPlayer({
src,
title,
subtitle,
visualizer,
captions,
captionsLang,
captionsLabel,
defaultMuted,
autoPlay,
onPlay,
onPause,
onEnded,
className,
}: AudioPlayerProps): JSX.Element
props— Component props (seeAudioPlayerProps).
Injection Notes
Requirements
Peer dependencies:
@molecule/app-audio^1.0.0@molecule/app-logger^1.0.0@molecule/app-react^4.13.0 || ^5.0.0@molecule/app-ui^1.16.0@molecule/app-ui-react^4.14.0@molecule/app-utilities^1.1.0react^18.0.0 || ^19.0.0
Runtime Dependencies
@molecule/app-audio@molecule/app-logger@molecule/app-react@molecule/app-ui@molecule/app-ui-react@molecule/app-utilitiesreact
Pass a React node to visualizer to render a waveform above the controls.
The time display shows 0:00 until playback metadata arrives.
Browsers can block autoPlay until the first user interaction.
On React Native, bond an @molecule/app-audio provider at startup. Expo apps
can use @molecule/app-audio-expo and a device-accessible media URL.
Translations come from the companion @molecule/app-locales-audio-player
locale bond.
E2E Tests
- Play, pause, seek, mute and unmute a track from both renderers.
- Confirm elapsed time, duration, captions and the end callback follow playback.
Translations
Translation strings are provided by @molecule/app-locales-audio-player.