Expand description
Decodes audio samples from various audio file formats.
This module provides decoders for common audio formats like MP3, WAV, Vorbis and FLAC. It supports both one-shot playback and looped playback of audio files.
§Usage
The simplest way to decode files (automatically sets up seeking and duration):
use std::fs::File;
use rodio::Decoder;
let file = File::open("audio.mp3").unwrap();
let decoder = Decoder::try_from(file).unwrap(); // Automatically sets byte_len from metadata
For more control over decoder settings, use the builder pattern:
use std::fs::File;
use rodio::Decoder;
let file = File::open("audio.mp3").unwrap();
let len = file.metadata().unwrap().len();
let decoder = Decoder::builder()
.with_data(file)
.with_byte_len(len) // Enable seeking and duration calculation
.with_seekable(true) // Enable seeking operations
.with_hint("mp3") // Optional format hint
.with_gapless(true) // Enable gapless playback
.build()
.unwrap();
§Features
The following audio formats are supported based on enabled features:
wav
- WAV format supportflac
- FLAC format supportvorbis
- Vorbis format supportmp3
- MP3 format support via minimp3symphonia
- Enhanced format support via the Symphonia backend
When using symphonia
, additional formats like AAC and MP4 containers become available
if the corresponding features are enabled.
Re-exports§
pub use builder::DecoderBuilder;
pub use builder::Settings;
Modules§
Structs§
- Decoder
- Source of audio samples decoded from an input stream. See the module-level documentation for examples and usage.
- Looped
Decoder - Source of audio samples from decoding a file that never ends. When the end of the file is reached, the decoder starts again from the beginning.
Enums§
- Decoder
Error - Errors that can occur when creating a decoder.