API and Development
WaveformPlayer from @prepared911/ui-audio-player wraps @wavesurfer/react to render an interactive audio waveform. Optional plugins add hover time labels, zoom, draggable regions, and a timeline ruler. An imperative ref exposes play, pause, seekTo, duration queries, and more for parent-driven workflows.
Name | Type | Default | Description |
|---|---|---|---|
|
| — | URL to the audio file |
|
|
| Color applied to the region matching |
|
| — | Id of the region that should be visually highlighted as active. The matching region's color
is replaced with |
|
|
| Enable click-to-seek on the waveform (default: true) |
|
|
| Enable drag selection for creating regions |
|
|
| Waveform height in pixels (default: 96) |
|
| — | Hover plugin options |
|
|
| When the waveform is already shown ( |
|
|
| Maximum zoom level |
|
|
| Minimum zoom level |
|
|
| Whether to normalize waveform (default: true) |
|
| — | Callback when playback reaches the end |
|
| — | Callback when an error occurs |
|
| — | Callback when playback state changes |
|
| — | Callback when wavesurfer is ready |
|
| — | Callback when a region is created (via drag selection or programmatically) |
|
| — | Callback when regions plugin is ready |
|
| — | Callback when user seeks to a new position |
|
| — | Callback when current time changes during playback |
|
| — | Callback when zoom level changes (from scroll wheel) |
|
|
| Array of plugins to enable |
|
|
| Array of regions to display |
|
| — | Timeline plugin options |
|
|
| Current zoom level in pixels per second |
|
| — | Zoom plugin options |
Interactive examples and edge cases for this component are in Storybook.
| Name | Type | Default | Description |
|---|---|---|---|
audioUrl | string | required | HTTP(S) URL to the audio file. Empty or invalid URLs show an error state. |
plugins | WaveformPlugin[] | [] | Enable Hover, Zoom, Regions, Timeline (see WaveformPlugin enum). |
zoomLevel | number | 50 | Current zoom (pixels per second); paired with minZoom / maxZoom. |
minZoom | number | 10 | Lower zoom bound. |
maxZoom | number | 1000 | Upper zoom bound. |
onZoomChange | (zoom: number) => void | — | Fires when zoom changes (e.g. scroll wheel). |
zoomOptions | WaveformZoomOptions | — | Zoom plugin sensitivity (scale). |
regions | WaveformRegion[] | — | Static regions when Regions plugin is enabled. |
onRegionsPluginReady | (plugin: RegionsPlugin) => void | — | Regions plugin instance for advanced APIs. |
onRegionCreated | (region: Region) => void | — | After drag-selection or programmatic create. |
enableDragSelection | boolean | false | Allow drag-to-create regions. |
timelineOptions | WaveformTimelineOptions | — | Tick intervals and labels for the timeline plugin. |
hoverOptions | WaveformHoverOptions | — | Hover cursor line and label styling. |
height | number | 96 | Waveform height in pixels. |
normalize | boolean | true | Normalize waveform amplitude. |
onReady | (ws: WaveSurfer) => void | — | WaveSurfer ready callback. |
onError | (error: Error) => void | — | Load or runtime errors. |
onPlayingChange | (isPlaying: boolean) => void | — | Play state changes. |
onTimeChange | (currentTime: number) => void | — | Time updates during playback. |
onSeek | (time: number) => void | — | User seek position. |
onEnded | () => void | — | Playback completed. |
clickToSeek | boolean | true | Click waveform to seek. |
Use forwardRef + WaveformPlayerRef for play, pause, playPause, stop, seekTo, getCurrentTime, getDuration, isPlaying, etc.