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
| Prop | Type | Default | Description |
|---|---|---|---|
source (required) | ViewerSource | The audio: a URL, a File/Blob, or bytes. | |
artwork | ReactNode | Cover art. | |
bordered | boolean | Draw the player as a bordered card. Default true. | |
className | string | ||
description | ReactNode | A second line, e.g. the artist or a date. | |
loop | boolean | ||
peaks | readonly number[] | Precomputed peaks for the waveform, instead of decoding the file. | |
title | string | Title shown above the controls. Defaults to the file name. | |
waveform | boolean | Draw 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