mirror of
https://github.com/RustAudio/rodio
synced 2024-12-12 21:22:36 +00:00
improved error handling
This commit is contained in:
parent
3bc964737c
commit
5f1b057b14
1 changed files with 14 additions and 10 deletions
|
@ -2,7 +2,7 @@ use std::time::Duration;
|
||||||
use symphonia::{
|
use symphonia::{
|
||||||
core::{
|
core::{
|
||||||
audio::{AudioBufferRef, SampleBuffer, SignalSpec},
|
audio::{AudioBufferRef, SampleBuffer, SignalSpec},
|
||||||
codecs::{Decoder, CODEC_TYPE_NULL},
|
codecs::{Decoder, DecoderOptions, CODEC_TYPE_NULL},
|
||||||
errors::Error,
|
errors::Error,
|
||||||
formats::{FormatOptions, FormatReader, SeekedTo},
|
formats::{FormatOptions, FormatReader, SeekedTo},
|
||||||
io::MediaSourceStream,
|
io::MediaSourceStream,
|
||||||
|
@ -77,13 +77,19 @@ impl SymphoniaDecoder {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Select the first supported track
|
// Select the first supported track
|
||||||
let track_id = probed
|
let track_id = match probed
|
||||||
.format
|
.format
|
||||||
.tracks()
|
.tracks()
|
||||||
.iter()
|
.iter()
|
||||||
.find(|t| t.codec_params.codec != CODEC_TYPE_NULL)
|
.find(|t| t.codec_params.codec != CODEC_TYPE_NULL)
|
||||||
.unwrap()
|
{
|
||||||
.id;
|
Some(track) => track.id,
|
||||||
|
None => {
|
||||||
|
return Err(symphonia::core::errors::Error::Unsupported(
|
||||||
|
"No track with supported codec",
|
||||||
|
))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let track = probed
|
let track = probed
|
||||||
.format
|
.format
|
||||||
|
@ -92,8 +98,8 @@ impl SymphoniaDecoder {
|
||||||
.find(|track| track.id == track_id)
|
.find(|track| track.id == track_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut decoder =
|
let mut decoder = symphonia::default::get_codecs()
|
||||||
symphonia::default::get_codecs().make(&track.codec_params, &Default::default())?;
|
.make(&track.codec_params, &DecoderOptions::default())?;
|
||||||
let total_duration = stream
|
let total_duration = stream
|
||||||
.codec_params
|
.codec_params
|
||||||
.time_base
|
.time_base
|
||||||
|
@ -104,10 +110,8 @@ impl SymphoniaDecoder {
|
||||||
let decoded = loop {
|
let decoded = loop {
|
||||||
let current_frame = match probed.format.next_packet() {
|
let current_frame = match probed.format.next_packet() {
|
||||||
Ok(packet) => packet,
|
Ok(packet) => packet,
|
||||||
Err(e) => match e {
|
Err(Error::IoError(_)) => break decoder.last_decoded(),
|
||||||
Error::IoError(_) => break decoder.last_decoded(),
|
Err(e) => return Err(e),
|
||||||
_ => return Err(e),
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// If the packet does not belong to the selected track, skip over it
|
// If the packet does not belong to the selected track, skip over it
|
||||||
|
|
Loading…
Reference in a new issue