Duration #40
@@ -1,9 +1,23 @@
|
|||||||
|
use lofty::file::AudioFile;
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct Duration {
|
pub struct Duration {
|
||||||
pub val: i32
|
pub val: i32
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_duration(song_path: &String) -> Duration {
|
pub fn get_duration(song_path: &String) -> Result<std::time::Duration,std::io::Error> {
|
||||||
Duration::default()
|
match std::fs::File::open(song_path) {
|
||||||
|
Ok(mut content) => match lofty::flac::FlacFile::read_from(&mut content, lofty::config::ParseOptions::new(),) {
|
||||||
|
Ok(flac_file) => {
|
||||||
|
let properties = flac_file.properties();
|
||||||
|
Ok(properties.duration())
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
Err(std::io::Error::other(err.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
Err(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user