Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect total_duration while using symphonia features #601

Open
Kamil729 opened this issue Aug 8, 2024 · 1 comment
Open

Incorrect total_duration while using symphonia features #601

Kamil729 opened this issue Aug 8, 2024 · 1 comment
Assignees
Labels

Comments

@Kamil729
Copy link

Kamil729 commented Aug 8, 2024

While using rodio with symphonia features enabled values reported by Decoder::total_duration are incorrect. It works fine while using other backends. Calculating it with symphonia directly also return correct value. Minimum example with 7s long, flac file:

Cargo.toml
[dependencies]
rodio = { version = "0.19.0", default-features = false, features = [
    "symphonia-all",
] }
main.rs
use std::{fs::File, io::BufReader, path::PathBuf, str::FromStr, time::Duration};

use rodio::{Decoder, Source};

fn main() {
    let track_path = PathBuf::from_str("test.flac").unwrap();
    let file = BufReader::new(File::open(track_path).unwrap());
    let track_source = Decoder::new(file).unwrap();
    let track_duration = track_source.total_duration();
    let real_duration = Some(Duration::from_secs(7));

    assert_eq!(track_duration, real_duration);
}
Output
thread 'main' panicked at src/main.rs:12:5:
assertion `left == right` failed
  left: Some(11.294967295s)
 right: Some(7s)

Audio file
More complex example and comparison with symphonia

@dvdsk dvdsk added the bug label Aug 9, 2024
@dvdsk dvdsk self-assigned this Aug 9, 2024
@dvdsk
Copy link
Collaborator

dvdsk commented Aug 9, 2024

Very nice bug report! I had a quick look and I think I see the issue. I suspect the problem is that rodio uses the default_track (probed.format.default_track()) to calculate the total_duration. While for playback we do the same as your symphonia code. That is we pick the first track that has a codec type unequal to CODEC_TYPE_NULL.

Ill add a test and see if I can fix it, when I have time but I have to work through a PR first. If you want to take a crack at it yourself, it should be relatively easy. If you do please write a test and see if the current assets (in the assets folder) do give the correct duration (they probably do not 😓). On the off chance they do work please add your Audio file to the assets.

Ps; Its totally fine if you rather not work on this, I am already very happy with the extremely clear bug report you just gave us 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants