hint from file extension

This commit is contained in:
Breval Ferrari 2025-03-19 00:45:04 -04:00
parent 9130f52f66
commit fe1ee27d80
No known key found for this signature in database
GPG key ID: F71E304D6400AB8E
2 changed files with 19 additions and 3 deletions

View file

@ -18,7 +18,7 @@ thiserror = "2.0"
derive-new = "0.7"
strum = { version = "0.26", features = ["derive"] }
derive_wrapper = "0.1"
symphonia = { version = "0.5.4", features = ["all"] }
symphonia = { version = "0.5", features = ["all"] }
[dev_dependencies]
project-root = "0.2.2"

View file

@ -58,7 +58,13 @@ impl Audio {
let mss = MediaSourceStream::new(Box::new(mediasource), Default::default());
let reader = probe
.format(
&Default::default(),
&Hint::new().with_extension(
path.as_ref()
.extension()
.map(|os_str| os_str.to_str())
.flatten()
.unwrap_or("mp3"),
),
mss,
&Default::default(),
&Default::default(),
@ -179,6 +185,16 @@ mod tests {
#[test]
fn open_sample_file() {
assert_eq!(Ok(include_bytes!("../../../testing material/sound/1938-04-30_BBC_Winston_Churchill_To_The_Royal_Academy_Of_Arts.mp3").to_vec()), Audio::open(get_project_root().expect("can't find project root!").join("testing material").join("sound").join("1938-04-30_BBC_Winston_Churchill_To_The_Royal_Academy_Of_Arts.mp3")).map(|audio| audio.into_data_bytes()));
assert_eq!(
Ok(include_bytes!("../../../testing material/sound/sample-3s.mp3").to_vec()),
Audio::open(
get_project_root()
.expect("can't find project root!")
.join("testing material")
.join("sound")
.join("sample-3s.mp3")
)
.map(|audio| audio.into_data_bytes())
);
}
}