Skip to main content

Overview

The audio playback system provides a complete set of controls for playing audio files and navigating through transcripts. It features a custom scrub bar for precise seeking, play/pause controls, and automatic time synchronization.

Audio Component

The viewer uses a hidden HTML5 audio element controlled by React:

Audio Props Configuration

The audio element is configured automatically by the container:

Play/Pause Control

The play/pause button automatically toggles based on playback state:

Usage

Displays a Play or Pause icon automatically.

Playback Control Functions

The viewer hook provides imperative playback controls:

Scrub Bar

The scrub bar provides visual feedback and seeking capabilities:

Scrub Bar Components

  • ScrubBarContainer: Handles mouse/touch events for scrubbing
  • ScrubBarTrack: The background track
  • ScrubBarProgress: Visual indicator of playback progress
  • ScrubBarThumb: Draggable handle for seeking
  • ScrubBarTimeLabel: Formatted time display

Customization

Seeking Functionality

Seek to Time

Seek to a specific time in seconds:

Seek to Word

Jump to a specific word in the transcript:
This enables clickable words in the transcript:

Scrubbing State Management

When the user drags the scrub bar, the RAF loop is paused for performance:
The isScrubbing state can be used to show visual feedback during seeking, such as a larger preview or tooltip.

Audio Event Handling

The viewer listens to all relevant audio events:

Duration Fallback

If audio metadata isn’t loaded, the viewer uses alignment data as fallback:

State Synchronization

The viewer maintains multiple state sources:
When seeking:
  1. Update React state (currentTime)
  2. Update current word index via handleTimeUpdate
  3. Update audio element’s currentTime
Always update state before updating the audio element’s currentTime to ensure the UI is in sync when the “seeked” event fires.

Complete Example

Here’s a full playback interface:

Next Steps