AudioPlayer

Audio with a waveform you can click to seek, plus play, time, volume and speed controls.

Status: beta. Category: Viewers.

import { AudioPlayer, Waveform } from '@glyphui/viewers/media'

Exports: AudioPlayer, audioPlayerStyles, Waveform, waveformStyles, computePeaks.

Notes

  • No extra packages needed. Waveforms decode the file with the Web Audio API; pass peaks to skip that.
  • The waveform is a slider: click or drag to seek, or use the arrow keys.

AudioPlayer props

PropTypeDefaultDescription
source (required)ViewerSourceThe audio: a URL, a File/Blob, or bytes.
artworkReactNodeCover art.
borderedbooleanDraw the player as a bordered card. Default true.
classNamestring
descriptionReactNodeA second line, e.g. the artist or a date.
loopboolean
peaksreadonly number[]Precomputed peaks for the waveform, instead of decoding the file.
titlestringTitle shown above the controls. Defaults to the file name.
waveformbooleanDraw a waveform you can click to seek. Default true.

Example: Voice note

The waveform is decoded in the browser.

import { AudioPlayer } from '@glyphui/viewers/media'
import { fixture } from '../../../lib/fixtures'

export default function Example() {
  return (
    <AudioPlayer
      source={fixture('chime.wav')}
      title="Standup notes"
      description="Recorded Oct 17 · 6 seconds"
      className="w-full max-w-lg"
    />
  )
}

Example: Waveform alone

Precomputed peaks, e.g. from your server, with your own playback state.

import { Waveform } from '@glyphui/viewers/media'
import { useState } from 'react'

const peaks = Array.from(
  { length: 80 },
  (_, i) => 0.25 + 0.75 * Math.abs(Math.sin(i / 6)) * (1 - i / 120),
)

export default function Example() {
  const [time, setTime] = useState(12)
  return (
    <div className="grid w-full max-w-lg gap-2 text-primary">
      <Waveform
        peaks={peaks}
        currentTime={time}
        duration={40}
        onSeek={setTime}
        label="Call recording position"
      />
      <span className="text-caption text-muted-foreground tabular-nums">
        {Math.round(time)}s of 40s
      </span>
    </div>
  )
}

Live page: https://glyphui.xyz/components/audio-player