useAudioTracks hook handles fetching audio files, decoding them, and creating ClipTrack objects for the playlist. It supports progressive loading, pre-loaded buffers, and peaks-first rendering.
useAudioTracks
Load audio from URLs or AudioBuffers and convert to ClipTrack format.Import
Basic Usage
Progressive Loading
Show tracks as they load instead of waiting for all to finish:Pre-loaded AudioBuffers
Skip fetch and decode by providing AudioBuffers directly:Peaks-First Rendering
Render waveforms instantly using pre-computed peak data:Multi-Clip Timeline
Position clips at specific times with offsets and durations:With Fades and Effects
Spectrogram Rendering
Parameters
AudioTrackConfig
Configuration for a single audio track.URL to audio file. Used if
audioBuffer is not provided.Pre-loaded AudioBuffer. Skips fetch and decode if provided.
Display name for the track. Defaults to
"Track N".Whether the track starts muted.
Whether the track starts soloed.
Track volume (0-1).
Stereo pan position (-1 to 1, where -1 is left, 0 is center, 1 is right).
Waveform color (CSS color value).
Function to set up audio effects chain for this track.
When the clip starts on the timeline (in seconds).
Duration of the clip in seconds. Defaults to full audio duration.
Offset into the source audio file in seconds.
Fade in configuration.
Fade out configuration.
Pre-computed waveform data in BBC audiowaveform format. For peaks-first rendering, provide this without
audioBuffer or src. Sample rate and duration are derived from the waveform data.Visualization render mode.
Spectrogram configuration (FFT size, window function, frequency scale, etc.).
Spectrogram color map name or custom color array.
UseAudioTracksOptions
When
true, tracks are added to the playlist as they load, rather than waiting for all tracks to finish loading.Return Value
Array of loaded tracks ready for
WaveformPlaylistProvider.Whether tracks are currently loading.
Error message if loading failed, otherwise
null.Number of tracks that have finished loading.
Total number of tracks to load.
Loading Strategies
The hook supports three loading strategies:- URL-based loading - Provide
src, hook fetches and decodes - Pre-loaded buffers - Provide
audioBuffer, skip fetch/decode - Peaks-first rendering - Provide
waveformDataonly, audio loads later
AbortController Cleanup
The hook usesAbortController to cancel in-flight fetches on unmount or when configs change. This prevents memory leaks and race conditions.
Related
- Effects Hooks - Add dynamic effects to tracks
- WaveformPlaylistProvider - Playlist context provider