Upgrading from 0.20 or earlier to 0.21.1 involves several significant changes to features, output streams, and decoders.
Features and Decoders
- Playback: Playback logic is now a feature enabled by default. If you use
default_features = false, you must explicitly add features = ["playback"] to your Cargo.toml. - Decoders: The default decoders are now Symphonia (MPL licensed). To use the old decoders, set
default_features = false and enable claxon (FLAC), hound (WAV), and lewton (Ogg Vorbis) in Cargo.toml.
OutputStream Changes
OutputStreamHandle has been removed.OutputStreamHandle::play_raw is removed; use OutputStream.mixer().add() instead.- Recommended way to open a stream: Use
OutputStreamBuilder::open_default_stream()?. - Legacy behavior: To replicate old behavior, use
open_stream_or_fallback()? by manually getting the default device via cpal and passing it to OutputStreamBuilder::from_device(default_device)?. - Logging: The output stream now prints to stderr or logs on drop. To disable this, use
stream.log_on_drop(false).
Sink and SpatialSink
- Replace
Sink::try_new with Sink::connect_new, passing an &Mixer (obtained via OutputStream.mixer()). - Replace
Sink::new_idle with Sink::new.
Example Migration (0.20 to 0.21):
Old (0.20):
let (_stream, handle) = rodio::OutputStream::try_default()?;
let player = rodio::Player::try_new(&handle)?;
New (0.21):
let stream_handle = rodio::OutputStreamBuilder::open_default_stream()?;
let player = rodio::Player::connect_new(stream_handle.mixer());
Decoder Changes
Decoder::new_mp4 no longer accepts an Mp4Type hint.- Symphonia decoders no longer assume sources are seekable. Use
DecoderBuilder::with_seekable or try_from on a File. You no longer need BufReader.
Example Migration (0.20 to 0.21):
Old (0.20):
let file = File::open("music.ogg")?;
let reader = BufReader::new(file);
let source = Decoder::new(reader);
New (0.21):
let file = File::open("music.ogg")?;
let source = Decoder::try_from(file)?;
Other Changes
- DynamicMixer: Replace
DynamicMixerController with Mixer and DynamicMixer with MixerSource. - Noise:
Source::white and Source::pink are deprecated. Use WhiteUniform::new and Pink::new. - Source Trait:
current_frame_len is renamed to current_span_len.- The
Source trait is no longer generic over sample types (f32, u16, i16). It now works exclusively with f32. Remove any sample type generics, SampleConvertor usage, or convert_samples calls.