Fixed an issue with CUE playback, fixed an issue with CUE file reading

The CUE artist was being inserted as the Album title
This commit is contained in:
G2-Games 2023-12-05 08:19:10 -06:00
parent 38b27c66c2
commit d87927a7db
2 changed files with 21 additions and 11 deletions

View file

@ -73,8 +73,8 @@ impl Player {
let end: Arc<RwLock<Option<Duration>>> = Arc::new(RwLock::new(None));
let position_update = position.clone();
let start_update = start.clone();
let end_update = end.clone();
let start_update = Arc::clone(&start);
let end_update = Arc::clone(&end);
let (message_tx, message_rx) = bounded(1);
std::thread::spawn(move || {
loop {
@ -88,8 +88,6 @@ impl Player {
&& start_update.read().unwrap().is_some()
&& end_update.read().unwrap().is_some()
{
if let Some(time) = *start_update.read().unwrap() { pos_temp = Some(pos_temp.unwrap() - time) }
let atf = end_update.read().unwrap().unwrap() - Duration::milliseconds(100);
if pos_temp.unwrap() >= end_update.read().unwrap().unwrap() {
message_tx.try_send(PlayerCmd::Eos).unwrap();
@ -102,10 +100,16 @@ impl Player {
*end_update.write().unwrap() = None;
} else if pos_temp.unwrap() >= atf {
match message_tx.try_send(PlayerCmd::AboutToFinish) {
Ok(_) => println!("Sent ATF"),
Err(err) => println!("{}", err),
Ok(_) => (),
Err(_) => (),
}
}
// This has to be done AFTER the current time in the file
// is calculated, or everything else is wrong
if let Some(time) = *start_update.read().unwrap() {
pos_temp = Some(pos_temp.unwrap() - time)
}
}
*position_update.write().unwrap() = pos_temp;
@ -159,11 +163,14 @@ impl Player {
self.pause().unwrap();
// Wait for it to be ready, and then move to the proper position
while self.playbin.read().unwrap().query_duration::<ClockTime>().is_none() {
let now = std::time::Instant::now();
while now.elapsed() < std::time::Duration::from_millis(20) {
if self.seek_to(Duration::from_std(*start).unwrap()).is_ok() {
return;
}
std::thread::sleep(std::time::Duration::from_millis(1));
};
self.seek_to(Duration::from_std(*start).unwrap()).unwrap();
}
panic!("Couldn't seek to beginning of cue track in reasonable time (>20ms)");
},
_ => {
self.playbin.write().unwrap().set_property("uri", source.as_uri());

View file

@ -149,6 +149,7 @@ impl Song {
self.tags.get(target_key)
}
/// Gets an internal field from a song
pub fn get_field(&self, target_field: &str) -> Option<Field> {
let lower_target = target_field.to_lowercase();
match lower_target.as_str() {
@ -164,10 +165,12 @@ impl Song {
}
}
/// Sets the value of a tag in the song
pub fn set_tag(&mut self, target_key: Tag, new_value: String) {
self.tags.insert(target_key, new_value);
}
/// Deletes a tag from the song
pub fn remove_tag(&mut self, target_key: &Tag) {
self.tags.remove(target_key);
}
@ -648,7 +651,7 @@ impl MusicLibrary {
}
match album_artist {
Some(artist) => {
tags.insert(Tag::Album, artist.clone());
tags.insert(Tag::Artist, artist.clone());
}
None => (),
}