rodio icon indicating copy to clipboard operation
rodio copied to clipboard

Calculate duration for mp3s

Open kuviman opened this issue 2 years ago • 1 comments

Currently, the duration is not calculated for mp3s when using symphonia

kuviman avatar Feb 19 '23 11:02 kuviman

Will someone please merge this.

ryankopf avatar Nov 27 '23 01:11 ryankopf

First off all, sorry this took a while we are short on maintainers. Thanks for making a PR though! Part of what you did in this PR overlaps with #513 (which has been merged).

This:

use std::io::BufReader;

use rodio::Source;

fn main() {
    let (_stream, handle) = rodio::OutputStream::try_default().unwrap();
    let sink = rodio::Sink::try_new(&handle).unwrap();

    let file = std::fs::File::open("assets/music.mp3").unwrap();
    let source = rodio::Decoder::new(BufReader::new(file)).unwrap();
    dbg!(source.total_duration());
    sink.append(source);

    sink.sleep_until_end();
}

prints:

[examples/music_mp3.rs:11:5] source.total_duration() = Some(
    10.000000006s,
)

Which is correct for the music.mp3 test file.

And that's good news! That means we get a duration for mp3 files without introducing the overhead of implementing bytes_len().

@kuviman if I am wrong and total_duration is not working for you on the latest master branch commit please reopen this or let me known in some other way!

dvdsk avatar Apr 10 '24 10:04 dvdsk