Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
MoosicBox Player
A high-performance audio playback engine with support for multiple audio formats and session-based playback management.
Overview
The MoosicBox Player is the core audio playback component that provides:
- Multi-Format Playback: Support for FLAC, AAC, MP3, and Opus
- Session Management: Handle concurrent playback sessions with state tracking
- Quality Control: Dynamic format conversion and sample rate resampling
- Local & Remote Playback: Play files directly or stream from remote sources
- HTTP API Integration: Control playback via REST endpoints
Features
Audio Format Support
The player supports the following audio formats (when corresponding feature flags are enabled):
- FLAC - Lossless high-quality audio (
decoder-flac,encoder-flac) - AAC/M4A - Efficient lossy compression (
decoder-aac,encoder-aac) - MP3 - Universal compatibility (
decoder-mp3,encoder-mp3) - Opus - Modern low-latency codec (
decoder-opus,encoder-opus)
Playback Features
- Gapless Playback - Seamless transitions between tracks
- Seek Support - Precise position control within tracks
- Volume Control - Per-session volume management
- Pause/Resume - Full playback state control
- Queue Management - Play albums, tracks, or playlists
- Progress Tracking - Real-time playback position updates
Session Management
- Multiple Sessions - Support concurrent playback sessions
- Session State - Track playing status, position, volume, and quality
- Playback Targets - Direct playback to specific audio zones
- Event System - Broadcast playback state changes to listeners
Core Types
PlaybackHandler
The main interface for controlling playback:
use ;
// Create a player implementation (e.g., LocalPlayer)
let mut handler = new;
// Control playback
handler.play_track.await?;
handler.pause.await?;
handler.resume.await?;
handler.seek.await?;
handler.next_track.await?;
handler.previous_track.await?;
handler.stop.await?;
Player Trait
Implement this trait to create custom player backends:
Playback
The state object for active playback:
Usage
Local Player
The LocalPlayer (available with the local feature) plays audio directly using the audio output backend:
use ;
use LocalPlayer;
use default_output_factory;
use PlaybackQuality;
async
Playing Tracks
use PlaybackHandler;
use ;
async
Playing Albums
use MusicApi;
use Id;
async
Controlling Playback
use DEFAULT_PLAYBACK_RETRY_OPTIONS;
async
Updating Playback State
async
Event Handling
Listen for playback state changes:
use ;
use UpdateSession;
// Register event listener
on_playback_event;
HTTP API Integration
When used with the MoosicBox Server, the player provides REST endpoints for playback control.
All endpoints require a profile via either moosicbox-profile header or moosicboxProfile query parameter.
Play Track
&sessionId=1&trackId=123&volume=0.8
Play Album
&sessionId=1&albumId=456&position=0
Play Multiple Tracks
&sessionId=1&trackIds=123,124,125&position=0
Pause/Resume
Seek
&seek=45.5
Next/Previous Track
Stop
Get Status
Update Playback
&playing=true&position=2&volume=0.7
Configuration
Feature Flags
The player supports various feature flags for customization:
Audio Output Backends:
cpal- Cross-platform audio output (default)jack- JACK audio server supportasio- ASIO low-latency support (Windows)
Audio Decoders:
decoder-aac- AAC audio decodingdecoder-flac- FLAC audio decodingdecoder-mp3- MP3 audio decodingdecoder-opus- Opus audio decodingall-decoders- Enable all decoders
Audio Encoders:
encoder-aac- AAC audio encodingencoder-flac- FLAC audio encodingencoder-mp3- MP3 audio encodingencoder-opus- Opus audio encodingall-encoders- Enable all encoders
Other Features:
api- Enable HTTP API endpointsopenapi- Generate OpenAPI documentationlocal- Enable local player implementationprofiling- Enable performance profiling
PlayerSource
Configure where audio is sourced from:
use PlayerSource;
// Play local files
let source = Local;
// Stream from remote server
let source = Remote ;
PlaybackQuality
Specify output audio format:
use ;
let quality = PlaybackQuality ;
let quality = PlaybackQuality ;
PlaybackRetryOptions
Configure retry behavior for operations:
use PlaybackRetryOptions;
use Duration;
let retry_options = PlaybackRetryOptions ;
Error Handling
use PlayerError;
match handler.play_track.await
Architecture
The player is built on several key components:
- PlaybackHandler - High-level playback control interface
- Player trait - Pluggable player backend system
- LocalPlayer - Direct audio output implementation
- Symphonia integration - Audio decoding via symphonia
- Signal chain - Audio processing pipeline for format conversion
- Audio output - Hardware audio output via
moosicbox_audio_output
Dependencies
Key dependencies from Cargo.toml:
moosicbox_audio_decoder- Audio format decodingmoosicbox_audio_output- Audio output backendsmoosicbox_music_api- Music metadata and track fetchingmoosicbox_music_models- Track and album data modelsmoosicbox_session- Session and playlist managementmoosicbox_resampler- Sample rate conversionsymphonia- Audio codec supportactix-web- HTTP API endpoints (withapifeature)
See Also
- MoosicBox Audio Output - Audio output backends
- MoosicBox Audio Decoder - Audio format decoding
- MoosicBox Session - Session management
- MoosicBox Music API - Music metadata API