Decode audio samples from a file

[![symphonia-badge]][symphonia] [![cat-multimedia-badge]][cat-multimedia]

Measuring a clip's length or feeding it to an analyzer means decoding its samples, whatever the container. [symphonia][symphonia] probes the format, then turns packets into audio buffers. get_probe identifies the container from a Hint and a MediaSourceStream, returning a FormatReader. default_track picks the audio track and get_codecs builds a decoder for its CodecParameters. Each packet from next_packet goes to Decoder::decode, whose buffer reports its frame count. The wav feature compiles in only the WAV reader; enable the features matching the formats you need.

{{#include ../../crates/multimedia/audio/src/bin/decode.rs::71}}

Play an audio file

[![rodio-badge]][rodio] [![cat-multimedia-badge]][cat-multimedia]

Playing a notification sound means opening an output device and handing it a decoded source. [rodio][rodio] does both. DeviceSinkBuilder::open_default_sink opens the system's default output, play decodes the file and starts it on the device's mixer, and Player::sleep_until_end blocks until playback finishes. Dropping the sink stops anything still playing, so rodio warns about it on drop; MixerDeviceSink::log_on_drop turns the warning off once the wait has returned.

{{#include ../../crates/multimedia/playback/src/bin/play.rs}}

{{#include ../links.md}}