1- use std:: collections:: VecDeque ;
1+ use std:: collections:: { VecDeque } ;
22use std:: error:: Error ;
33use std:: mem:: MaybeUninit ;
44use std:: sync:: { Arc , Mutex } ;
@@ -11,7 +11,7 @@ use symphonia::core::codecs::DecoderOptions;
1111use symphonia:: core:: errors:: Error as SymphoniaError ;
1212use symphonia:: core:: formats:: FormatOptions ;
1313use symphonia:: core:: io:: MediaSourceStream ;
14- use symphonia:: core:: meta:: { MetadataOptions , StandardTagKey , Metadata } ;
14+ use symphonia:: core:: meta:: { MetadataOptions , StandardTagKey } ;
1515use symphonia:: core:: probe:: { Hint , ProbeResult } ;
1616
1717use cpal:: traits:: { DeviceTrait , HostTrait , StreamTrait } ;
@@ -29,7 +29,6 @@ pub struct AudioReader {
2929 source_buffer : Vec < VecDeque < f32 > > ,
3030
3131 position : usize ,
32- duration : u64 ,
3332 finished : bool ,
3433
3534 sample_rate : u32 ,
@@ -42,7 +41,7 @@ impl AudioReader {
4241
4342 let ( mut probe_result, mut decoder) = Self :: new_decoder ( src) ;
4443
45- let ( sample_rate, channel_count, duration , _) = Self :: load_info ( path, & mut decoder) ?;
44+ let ( sample_rate, channel_count, _ , _) = Self :: load_info ( path, & mut decoder, false ) ?;
4645
4746 let resampler = {
4847 let params = InterpolationParameters {
@@ -75,7 +74,6 @@ impl AudioReader {
7574 source_buffer : vec ! [ VecDeque :: new( ) ; channel_count] ,
7675
7776 position : 0 ,
78- duration,
7977 finished : false ,
8078
8179 sample_rate,
@@ -86,6 +84,7 @@ impl AudioReader {
8684 pub fn load_info (
8785 path : & str ,
8886 decoder : & mut Box < dyn symphonia:: core:: codecs:: Decoder > ,
87+ calculate_duration : bool
8988 ) -> Result < ( u32 , usize , u64 , TrackMetadata ) , Box < dyn Error > > {
9089 // read 1 packet to check the sample rate and channel count
9190 // TODO: there HAS to be a better way than opening the file twice
@@ -111,8 +110,10 @@ impl AudioReader {
111110
112111 // TODO: maybe cache this somewhere? idk
113112 let mut duration = 0 ;
114- while let Ok ( packet) = temp_probe. format . next_packet ( ) {
115- duration += packet. dur ;
113+ if calculate_duration {
114+ while let Ok ( packet) = temp_probe. format . next_packet ( ) {
115+ duration += packet. dur ;
116+ }
116117 }
117118
118119 let mut track_md = TrackMetadata :: default ( ) ;
0 commit comments