Overview
The AudioManager handles real-time audio playback synchronized with the video timeline. It uses the Web Audio API to mix multiple audio tracks, schedule audio clips with lookahead, and maintain synchronization during playback.The AudioManager is an internal manager that runs automatically. You typically don’t interact with it directly - use the PlaybackManager to control playback.
Architecture
Audio scheduling
The AudioManager uses a lookahead scheduling system:- Lookahead window: 2 seconds ahead of current playback time
- Schedule interval: 500ms (checks for new clips to schedule)
- Automatic synchronization: Maintains sync even during timeline changes
Audio graph
How it works
Initialization
The AudioManager automatically:- Subscribes to playback state changes
- Subscribes to timeline changes
- Subscribes to media asset changes
- Listens for seek events
Playback lifecycle
Timeline synchronization
When the timeline changes (elements added/removed/modified):- All active audio sinks are disposed
- If playback is active, audio restarts from the current time
- New audio clips are collected and scheduled
Seeking behavior
- During scrubbing: Audio is stopped
- Seek while playing: Audio restarts from the new time
- Seek while paused: Audio remains stopped
Volume control
Volume is controlled through the PlaybackManager:Audio format support
The AudioManager uses themediabunny library which supports all formats handled by the browser’s audio decoding capabilities:
- MP3
- WAV
- OGG
- AAC
- FLAC
- And more (depends on browser)
Performance considerations
Memory management
The AudioManager manages memory efficiently:- Audio buffers are cached per source file
- Clips share the same audio sink if they reference the same media file
- When timeline changes, unused sinks are disposed
- Audio iterators are cancelled when no longer needed
Scheduling precision
The lookahead system ensures smooth playback:- Audio is scheduled ahead of time to avoid gaps
- If decoding falls behind, playback waits to catch up
- Target ahead time: 1 second (buffers are paused if more than 1 second ahead)
Cleanup
The AudioManager automatically cleans up when:- Playback stops
- Timeline changes
- The editor is reset
Integration with other managers
The AudioManager integrates with:- PlaybackManager - Responds to play/pause/seek/volume changes
- TimelineManager - Collects audio clips from timeline tracks
- MediaManager - Retrieves audio files for playback
Technical details
Audio clips
Each audio clip has:Session IDs
Each playback session has a unique ID. This prevents old scheduled audio from playing after a seek or timeline change:Limitations
- Maximum lookahead: 2 seconds (to keep memory usage reasonable)
- Schedule interval: 500ms (cannot be adjusted)
- Requires Web Audio API support (all modern browsers)
See also
- PlaybackManager - Control playback and volume
- TimelineManager - Manage timeline tracks
- MediaManager - Manage media assets