Skip to content

Commit 3d13f3f

Browse files
committed
fix: turns out we *can* just get (approx) duration
1 parent 7285e82 commit 3d13f3f

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

‎player/src/main.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl Connection {
291291
self.ui_status_default();
292292
}
293293
},
294-
PlayState::Empty => unreachable!(),
294+
PlayState::Empty => unreachable!("done buffering when playstate empty"),
295295
}
296296
}
297297
AudioStatus::Finished => {
@@ -388,7 +388,7 @@ impl Connection {
388388
let file = path.into_os_string().into_string().unwrap();
389389

390390
if let Ok(mut reader) = AudioInfoReader::load(&file) {
391-
if let Ok((_, _, metadata)) = reader.read_info(true) {
391+
if let Ok((_, _, metadata)) = reader.read_info() {
392392
let track = protocol::Track {
393393
path: self.encrypt_path(file).unwrap(),
394394
owner: self.my_id.clone(),

‎player/src/transmit.rs‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,20 @@ impl AudioInfoReader {
5757
})
5858
}
5959

60-
pub fn read_info(
61-
&mut self,
62-
calculate_duration: bool,
63-
) -> Result<(u32, usize, TrackMetadata), Box<dyn Error>> {
60+
pub fn read_info(&mut self) -> Result<(u32, usize, TrackMetadata), Box<dyn Error>> {
6461
// read 1 packet to check the sample rate and channel count
6562
let packet = self.probe_result.format.next_packet()?;
6663
let decoded = self.decoder.decode(&packet)?;
6764
let spec = *decoded.spec();
6865

69-
// maybe check the duration
70-
let mut duration = 0;
71-
if calculate_duration {
72-
while let Ok(packet) = self.probe_result.format.next_packet() {
73-
duration += packet.dur;
74-
}
75-
}
66+
let duration = self
67+
.probe_result
68+
.format
69+
.default_track()
70+
.unwrap()
71+
.codec_params
72+
.n_frames
73+
.unwrap_or(0);
7674

7775
// seek back to start since we consumed packets
7876
self.probe_result.format.seek(
@@ -147,7 +145,7 @@ impl AudioReader {
147145
pub fn load(path: &str) -> Result<Self, Box<dyn Error>> {
148146
let mut info_reader = AudioInfoReader::load(path)?;
149147

150-
let (sample_rate, channel_count, _) = info_reader.read_info(false)?;
148+
let (sample_rate, channel_count, _) = info_reader.read_info()?;
151149

152150
let resampler = {
153151
let params = InterpolationParameters {

0 commit comments

Comments
 (0)