TurboStarter
For the complete documentation index, see llms.txt. Prefer markdown by appending .md to documentation URLs or sending Accept: text/markdown.

<AudioPlayer />

Composable audio player for web and mobile. Play, pause, skip, seek, and show time for generated speech or any audio file.

<AudioPlayer /> is a small, composable player for generated audio. Instead of one fixed widget, it gives you a provider that owns playback state and a set of primitives (play button, skip buttons, progress bar, time labels) that you arrange however your layout needs. It powers the player in the Speech app on both web and mobile.

Web

The web player is built on the native <audio> element and a Base UI slider. It includes the full set of primitives plus keyboard shortcuts.

Web audio player demo

Mobile

The mobile player uses expo-audio with the same provider-and-primitives API, plus playback rate control. It plays through the iOS silent switch, the same way a browser tab does.

Mobile audio player demo

Core principles

Composable by design

Place the button, progress bar, and time labels anywhere: in a bottom bar, a list row, or a compact inline card.

Honest playback state

Buffering, playing, and paused states come from the audio element itself, and the play button animates between them.

Smooth seeking

Dragging the progress bar pauses playback and resumes it when you let go, so scrubbing never stutters.

Keyboard shortcuts

The player supports keyboard shortcuts for playback control, such as Space to toggle playback and arrow keys to skip forward or backward.

Building blocks

Component / hookWebMobilePurpose
AudioPlayerProvider✓✓Owns the audio source and playback state. Takes src and autoPlay.
AudioPlayerButton✓✓Play/pause toggle with a buffering spinner.
AudioPlayerProgress✓✓Seekable progress bar.
AudioPlayerSkipButton✓Skips forward or backward by seconds (negative values rewind).
AudioPlayerTime✓Current playback time.
AudioPlayerDuration✓Total duration, or --:-- while it is unknown.
useAudioPlayer✓✓Playback API: play, pause, toggle, seek, skip, and state.
useAudioPlayerTime✓✓Current time, kept in a separate context so only time labels re-render.
useAudioPlayerShortcuts✓Space toggles playback, arrow keys skip.

The mobile useAudioPlayer also exposes setRate for playback speed.

Usage

import {
  AudioPlayerButton,
  AudioPlayerDuration,
  AudioPlayerProgress,
  AudioPlayerProvider,
  AudioPlayerSkipButton,
  AudioPlayerTime,
  useAudioPlayerShortcuts,
} from "@workspace/ui-web/audio-player";

const Controls = () => {
  useAudioPlayerShortcuts({ skipSeconds: 10 });

  return (
    <div className="flex flex-col gap-2">
      <div className="flex items-center justify-center gap-2">
        <AudioPlayerSkipButton seconds={-10} />
        <AudioPlayerButton />
        <AudioPlayerSkipButton seconds={10} />
      </div>
      <div className="flex items-center gap-2">
        <AudioPlayerTime />
        <AudioPlayerProgress />
        <AudioPlayerDuration />
      </div>
    </div>
  );
};

export const Player = ({ src }: { src: string }) => (
  <AudioPlayerProvider src={src} autoPlay>
    <Controls />
  </AudioPlayerProvider>
);
Prop / optionPurpose
srcAudio URL. undefined keeps the player empty.
autoPlayStarts playback when src changes.
secondsSkip distance for AudioPlayerSkipButton.
trackClassNameStyles the progress track.
indicatorClassNameStyles the filled part of the progress bar.
enabled / skipSecondsTurn the keyboard shortcuts on or off and set the skip length.

Shortcuts are ignored while focus is in an input, a button, or another control that handles the key itself.

To build your own control, read the state with useAudioPlayer() inside the provider:

const { isPlaying, isBuffering, duration, toggle, seek } = useAudioPlayer();

How is this guide?

Last updated on

On this page

Make AI your edge, not replacement.Try AI Kit