10 unstable releases (4 breaking)

0.5.0 Aug 27, 2020
0.4.0 Aug 26, 2020
0.3.5 Feb 20, 2020
0.3.3 May 8, 2019
0.1.0 Jan 31, 2018

#3 in Audio

Download history 2683/week @ 2020-06-07 2379/week @ 2020-06-14 2360/week @ 2020-06-21 3222/week @ 2020-06-28 2864/week @ 2020-07-05 3510/week @ 2020-07-12 3054/week @ 2020-07-19 3199/week @ 2020-07-26 3066/week @ 2020-08-02 4186/week @ 2020-08-09 5166/week @ 2020-08-16 5286/week @ 2020-08-23 5619/week @ 2020-08-30 4084/week @ 2020-09-06 4403/week @ 2020-09-13 4140/week @ 2020-09-20

16,888 downloads per month
Used in 16 crates (7 directly)

MIT license

69KB
1K SLoC

C 826 SLoC // 0.0% comments Rust 181 SLoC // 0.1% comments Shell 173 SLoC // 0.0% comments

minimp3 Rust bindings

Cargo package Cargo package Build Status

Usage example

# Cargo.toml

[dependencies]
minimp3 = "0.5"
use minimp3::{Decoder, Frame, Error};

use std::fs::File;

fn main() {
    let mut decoder = Decoder::new(File::open("audio_file.mp3").unwrap());

    loop {
        match decoder.next_frame() {
            Ok(Frame { data, sample_rate, channels, .. }) => {
                println!("Decoded {} samples", data.len() / channels)
            },
            Err(Error::Eof) => break,
            Err(e) => panic!("{:?}", e),
        }
    }
}

Async I/O

The decoder can be used with Tokio via the async_tokio feature flag.

# Cargo.toml

[dependencies]
minimp3 = { version = "0.4", features = ["async_tokio"] }

# tokio runtime
tokio = {version = "0.2", features = ["full"] }
use minimp3::{Decoder, Frame, Error};

use tokio::fs::File;

#[tokio::main]
async fn main() {
    let file = File::open("minimp3-sys/minimp3/vectors/M2L3_bitrate_24_all.bit").await.unwrap();
    let mut decoder = Decoder::new(file);

    loop {
        match decoder.next_frame_future().await {
            Ok(Frame {
                   data,
                   sample_rate,
                   channels,
                   ..
               }) => println!("Decoded {} samples", data.len() / channels),
            Err(Error::Eof) => break,
            Err(e) => panic!("{:?}", e),
        }
    }
}

Dependencies

~0.2–0.8MB
~15K SLoC