API Reference¶
AudioBackend Class¶
Main Class
The AudioBackend class is the primary interface for audio playback functionality.
Constructor¶
Creates a new instance of the AudioBackend player with default settings.
Methods¶
File Operations¶
load_file()
¶
Loads an audio file for playback.
Parameters:
file_path
(str): Path to the audio file
Returns:
bool
: True if file loaded successfully, False otherwise
Example:
Playback Control¶
play()
¶
Starts or resumes playback.
pause()
¶
Pauses playback.
stop()
¶
Stops playback and releases resources.
seek()
¶
Seeks to specified position.
Parameters:
position_ms
(int): Position to seek to in milliseconds
set_volume()
¶
Sets playback volume.
Parameters:
volume
(float): Volume level between 0.0 and 1.0
Callback Management¶
set_position_callback()
¶
Sets callback for position updates.
Parameters:
callback
(Callable[[int], None]): Function that receives position in milliseconds
set_playback_state_callback()
¶
Sets callback for playback state changes.
Parameters:
callback
(Callable[[bool], None]): Function that receives boolean playing state
set_end_of_track_callback()
¶
Sets callback for track end notification.
Parameters:
callback
(Callable[[], None]): Function called when track ends
Properties¶
duration
¶
Gets the duration of the current track in milliseconds.
position
¶
Gets the current playback position in milliseconds.
is_playing
¶
Gets the current playback state.
Technical Details¶
Buffer Management¶
Parameter | Size (frames) | Description |
---|---|---|
Default buffer | 65536 | Standard buffer size |
Minimum buffer | 32768 | Minimum allowed size |
Maximum buffer | 262144 | Maximum allowed size |
Prebuffer | 16384 | Initial buffer before playback |
Audio Parameters¶
Parameter | Value | Description |
---|---|---|
Default sample rate | 48000 Hz | Standard playback rate |
Maximum rate | 384000 Hz | Maximum supported rate |
Channels | 2 | Stereo output |
Error Recovery¶
The system includes:
- Automatic buffer underrun recovery
- Sample rate adaptation
- Stream recreation on errors
- Seek error handling