Prepared Docs

Prepared Docs

⌘K

    Loading navigation…

User

  1. Blocks
  2. Audio Player
  3. API and Development

Audio Player

API and Development

View Source
Submit Issue

AudioPlayer from @prepared911/ui-audio-player renders playback controls for emergency and dispatch audio. It supports URL strings, one or more clips with timeline alignment metadata, controlled or uncontrolled time and play state, optional skip controls, mute, and timestamp display modes. Recordings may include sensitive content; the component does not log audio URLs or onPressPlay results—callers must avoid sending those values to analytics or error reporters.

Props

Name

Type

Default

Description

audio

AudioPlayerAudioProp

—

Audio prop can be either: 1. An array or a single {@link AudioPlayerClip } (pre-loaded elements with absolute startedAt/endedAt for transcript alignment). 2. An array or a single URL string for simpler cases. URLs and elements may grant access to sensitive recordings. Do not log, persist in localStorage, or attach to DOM attributes for debugging.

activePlayerId

string | null

—

When set, identifies which player is globally active. When this changes to a different value than playerId, this player will stop. Clearing to null stops the player that was active. Use opaque IDs (e.g. chatroom or clip keys), not names, phone numbers, or free text — values may surface in React DevTools.

currentTime

number

—

Optional (for controlled mode). Current playback time in ms (global timeline)

description

string

—

Secondary line under the title (e.g. formatted date/time).

includePlaybackRates

boolean

—

When true, shows the playback-rate dropdown with the default rates [0.75, 1, 1.25, 1.5, 2].

isPlaying

boolean

—

Optional (for controlled mode). Whether playback is currently active.

onManualTimeScrub

((time: number) => void)

—

Callback when manual scrub occurs

onPlaybackRateChange

((rate: number) => void)

—

Fired when the user picks a new rate.

onPlayingChange

((playing: boolean) => void)

—

Callback when playback state changes

onPressNext

(() => void)

—

Next-track handler. When provided, shows the next-track button. Also used by shouldAutoPlayNext.

onPressPlay

(() => Promise<void | AudioPlayerAudioProp>)

—

Async callback invoked before playback starts (e.g. fetch signed or access-controlled URLs). If this returns audio URLs/clips, they will replace the current audio prop. If it returns void/undefined, the existing audio prop is used. Do not log return values or errors that embed URLs — they may grant access to sensitive audio.

onPressPrevious

(() => void)

—

Previous-track handler. When provided, shows the previous-track button.

onTimeChange

((time: number) => void)

—

Callback for every time change (via natural progression or manual scrub)

playbackRate

number

—

Controlled playback speed. When omitted, the player manages rate internally.

playerId

string

—

This player's ID for coordination with {@link AudioPlayerProps.activePlayerId}. Prefer an opaque identifier; avoid PII in this value.

shouldAutoPlayNext

boolean

false

When true, calls onPressNext automatically when the current audio finishes.

showTimeStamps

boolean

—

Show time stamps on the player

skipInterval

number

—

When set, shows skip backward/forward buttons that jump by this many milliseconds.

timeDisplayMode

TimeDisplayMode

TimeDisplayMode.Combined

Controls how timestamps are displayed when showTimeStamps is true. - combined (default): "00:15 / 01:30" shown together after the volume control - split: current time shown before the slider, total time shown after the slider

timeNotifyIntervalMs

number

—

Target ms between playback time samples (slider, timestamps, onTimeChange). Default 250. Values **under 250** use rAF + currentTime so intervals like 10–50 ms work; the timeupdate event alone is typically only ~4 Hz in browsers.

title

string

—

Title shown on the left of the bar (e.g. resource/seat name). Avoid PII you don't want in the DOM.

variant

AudioPlayerVariant

—

Layout variant. Omit for the standard inline bar (small icons, no section dividers). Minimal — play/pause only. Full — large icons and bordered sections per universal player mocks.

Storybook

Interactive examples and edge cases for this component are in Storybook.

Default
With Timestamps
With Urls For Audio Prop
With Prebuilt Audio Clips For Audio Prop
With Skip Controls
Minimal
With Imperative Ref
Minimal With On Press Play
Full Player

Markdown reference

NameTypeDefaultDescription
audioAudioPlayerAudioProprequiredURL string(s), AudioPlayerClip object(s), or arrays of either. Clips may include startedAt / endedAt for transcript alignment.
activePlayerIdstring | null—When set with playerId, only one player with matching coordination stays active; others stop. Use opaque IDs.
playerIdstring—This instance’s ID for coordination with activePlayerId.
currentTimenumber—Controlled mode: current time in ms on the global timeline.
isPlayingboolean—Controlled mode: whether playback is active.
minimalbooleanfalseWhen true, only play/pause (no slider, volume, timestamps).
showTimeStampsboolean—Show elapsed/total time when not minimal.
timeDisplayModeTimeDisplayModeCombinedCombined: single "current / total" block. Split: current before slider, total after.
skipIntervalnumber—If set, shows skip back/forward buttons advancing by this many milliseconds.
onPressPlay() => Promise<AudioPlayerAudioProp | void>—Runs before playback; may return new audio to replace the current prop (e.g. signed URLs).
onTimeChange(time: number) => void—Fires on playback progress and manual scrub.
onManualTimeScrub(time: number) => void—Fires when the user scrubs the slider.
onPlayingChange(playing: boolean) => void—Fires when play/pause state changes.

Also exported: TimeDisplayMode enum, formatAudioTime, formatDurationHumanReadable, and type guards isAudioClip, isStringArray, isClipArray.

Import

Full player (split time + skip)

Combined timestamps

Minimal player

Single-active coordination

Use minimal for compact rows (e.g. table cells) where scrubbing and volume are not required.

Full player with coordination

Pair playerId and activePlayerId (often from React state) so opening playback in one list item stops others.

Lazy URL resolution

Use onPressPlay to fetch a signed or access-controlled URL when the user starts playback; return the resolved audio value to replace the initial prop.

Previous

Audio Player / Usage

Next

Audio Player / Accessibility

On this page

Props
Storybook
Markdown reference
Import
Full player (split time + skip)
Combined timestamps
Minimal player
Single-active coordination
Full player with coordination
Lazy URL resolution