@@ -65,8 +65,28 @@ impl AudioInfoReader {
6565
6666 pub fn read_info ( & mut self ) -> Result < ( u32 , usize , TrackMetadata ) , Box < dyn Error > > {
6767 // read 1 packet to check the sample rate and channel count
68- let packet = self . probe_result . format . next_packet ( ) ?;
69- let decoded = self . decoder . decode ( & packet) ?;
68+
69+ let decoded = loop {
70+ let p = self . probe_result . format . next_packet ( ) ;
71+ match p {
72+ Ok ( packet) => {
73+ match self . decoder . decode ( & packet) {
74+ Ok ( decoded) => break decoded,
75+ Err ( _) => {
76+ // failed to decode, keep trying
77+ continue ;
78+ }
79+ }
80+ }
81+ Err ( SymphoniaError :: IoError ( _) ) => {
82+ // out of packets
83+ return Err ( "couldn't read any packets so we gave up :/" . into ( ) ) ;
84+ }
85+ Err ( e) => {
86+ return Err ( e. into ( ) ) ;
87+ }
88+ }
89+ } ;
7090 let spec = * decoded. spec ( ) ;
7191
7292 let duration = self
@@ -233,7 +253,7 @@ impl AudioReader {
233253 fn read_more ( & mut self ) -> Result < ( ) , Box < dyn Error > > {
234254 match self . inner . probe_result . format . next_packet ( ) {
235255 Ok ( packet) => {
236- let decoded = self . inner . decoder . decode ( & packet) . unwrap ( ) ;
256+ let decoded = self . inner . decoder . decode ( & packet) ? ;
237257 let spec = * decoded. spec ( ) ;
238258
239259 if decoded. frames ( ) > 0 {
@@ -314,9 +334,15 @@ impl AudioReader {
314334
315335 let mut pcm = [ 0.0 ; PCM_LENGTH ] ;
316336
317- let resampled = self . resample_more ( ) . unwrap ( ) ;
318- for i in 0 ..PCM_LENGTH {
319- pcm[ i] = resampled[ i] ;
337+ match self . resample_more ( ) {
338+ Ok ( resampled) => {
339+ for i in 0 ..PCM_LENGTH {
340+ pcm[ i] = resampled[ i] ;
341+ }
342+ }
343+ Err ( e) => {
344+ println ! ( "failed to encode frame: {:?}" , e) ;
345+ }
320346 }
321347
322348 let x = self . encoder . encode_vec_float ( & pcm, 256 ) . unwrap ( ) ;
0 commit comments