Decoding MP3 files
We'll start this chapter by learning how to decode an MP3 file to a format suitable to be played by the operating system using the simplemad
 crate, a binding for libmad
.
Adding dependencies
Let's add the following to Cargo.toml
:
crossbeam = "^0.3.0" pulse-simple = "^1.0.0" simplemad = "^0.8.1"
We also added the pulse-simple
and crossbeam
 crates because we'll need them later. The former will be used to play the songs with pulseaudio
and the latter will be used to implement the event loop of the music player engine.
We also need to add the following statements in main.rs
:
extern crate crossbeam; extern crate pulse_simple; extern crate simplemad; mod mp3;
In addition to the extern crate
statements, we have a mod
statement since we'll create a new module for the MP3 decoder.
Implementing an MP3 decoder
We're now ready to create this new module. Create a new mp3.rs
 file with the following content:
use std::io::{Read, Seek, SeekFrom}; use std::time::Duration; use simplemad;
We start...