mirror of
https://github.com/RustAudio/rodio
synced 2024-11-10 06:04:16 +00:00
fix formatting, error handling, and remove uneccesary features
This commit is contained in:
parent
6bbd95ed83
commit
3bc964737c
3 changed files with 20 additions and 10 deletions
|
@ -15,7 +15,7 @@ claxon = { version = "0.4.2", optional = true }
|
|||
hound = { version = "3.3.1", optional = true }
|
||||
lewton = { version = "0.10", optional = true }
|
||||
minimp3_fixed = { version = "0.5.4", optional = true}
|
||||
symphonia = { version = "0.5.4", optional = true, default-features = false, features = ["all"] }
|
||||
symphonia = { version = "0.5.4", optional = true, default-features = false, features = ["aac", "isomp4"] }
|
||||
crossbeam-channel = { version = "0.5.8", optional = true }
|
||||
thiserror = "1.0.49"
|
||||
|
||||
|
|
|
@ -77,16 +77,23 @@ impl SymphoniaDecoder {
|
|||
};
|
||||
|
||||
// Select the first supported track
|
||||
let track_id = probed.format.tracks()
|
||||
let track_id = probed
|
||||
.format
|
||||
.tracks()
|
||||
.iter()
|
||||
.find(|t| t.codec_params.codec != CODEC_TYPE_NULL).unwrap().id;
|
||||
.find(|t| t.codec_params.codec != CODEC_TYPE_NULL)
|
||||
.unwrap()
|
||||
.id;
|
||||
|
||||
let decode_opts = Default::default();
|
||||
let track = probed
|
||||
.format
|
||||
.tracks()
|
||||
.iter()
|
||||
.find(|track| track.id == track_id)
|
||||
.unwrap();
|
||||
|
||||
let track = probed.format.tracks().iter().find(|track| track.id == track_id).unwrap();
|
||||
|
||||
let mut decoder = symphonia::default::get_codecs()
|
||||
.make(&track.codec_params, &decode_opts)?;
|
||||
let mut decoder =
|
||||
symphonia::default::get_codecs().make(&track.codec_params, &Default::default())?;
|
||||
let total_duration = stream
|
||||
.codec_params
|
||||
.time_base
|
||||
|
@ -97,7 +104,10 @@ impl SymphoniaDecoder {
|
|||
let decoded = loop {
|
||||
let current_frame = match probed.format.next_packet() {
|
||||
Ok(packet) => packet,
|
||||
Err(_) => break decoder.last_decoded() // IoError end of stream is expected
|
||||
Err(e) => match e {
|
||||
Error::IoError(_) => break decoder.last_decoded(),
|
||||
_ => return Err(e),
|
||||
},
|
||||
};
|
||||
|
||||
// If the packet does not belong to the selected track, skip over it
|
||||
|
|
|
@ -10,4 +10,4 @@ fn test_mp4a_encodings() {
|
|||
let file = std::fs::File::open("assets/monkeys.mp4a").unwrap();
|
||||
let mut decoder = rodio::Decoder::new(BufReader::new(file)).unwrap();
|
||||
assert!(decoder.any(|x| x != 0)); // Assert not all zeros
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue