Small refactoring

This commit is contained in:
johannesd3 2021-02-02 02:19:15 +01:00
parent 3446864838
commit f67ceb5f6d

View file

@ -651,18 +651,14 @@ impl PlayerTrackLoader {
FileFormat::OGG_VORBIS_96, FileFormat::OGG_VORBIS_96,
], ],
}; };
let format = formats
.iter()
.find(|format| audio.files.contains_key(format))
.unwrap();
let file_id = match audio.files.get(&format) { let (format, file_id) = formats
Some(&file_id) => file_id, .iter()
None => { .find_map(|format| Some((format, *audio.files.get(&format)?)))
warn!("<{}> in not available in format {:?}", audio.name, format); .or_else(|| {
return None; warn!("<{}> is not available in any supported format", audio.name);
} None
}; })?;
let bytes_per_second = self.stream_data_rate(*format); let bytes_per_second = self.stream_data_rate(*format);
let play_from_beginning = position_ms == 0; let play_from_beginning = position_ms == 0;
@ -739,9 +735,8 @@ impl PlayerTrackLoader {
}; };
if position_ms != 0 { if position_ms != 0 {
match decoder.seek(position_ms as i64) { if let Err(err) = decoder.seek(position_ms as i64) {
Ok(_) => (), error!("Vorbis error: {}", err);
Err(err) => error!("Vorbis error: {:?}", err),
} }
stream_loader_controller.set_stream_mode(); stream_loader_controller.set_stream_mode();
} }