diff --git a/src/music_player/gstreamer.rs b/src/music_player/gstreamer.rs index db35c03..a503ae6 100644 --- a/src/music_player/gstreamer.rs +++ b/src/music_player/gstreamer.rs @@ -94,6 +94,7 @@ impl GStreamer { } // Make sure the playback tracker knows the stuff is stopped + println!("Beginning switch"); self.playback_tx.send(PlaybackInfo::Switching).unwrap(); let uri = self.playbin.read().unwrap().property_value("current-uri"); @@ -133,12 +134,11 @@ impl GStreamer { .unwrap() .set_property("uri", source.as_uri()); - self.play().unwrap(); + if self.state() != PlayerState::Playing { + self.play().unwrap(); + } - while uri.get::<&str>().unwrap_or("") - == self.property("current-uri").get::<&str>().unwrap_or("") - || self.position().is_none() - { + while self.raw_duration().is_none() { std::thread::sleep(std::time::Duration::from_millis(10)); } @@ -249,7 +249,7 @@ impl Player for GStreamer { .ok_or(PlayerError::Build)?; playbin.write().unwrap().set_property_from_value("flags", &flags); - playbin.write().unwrap().set_property("instant-uri", true); + //playbin.write().unwrap().set_property("instant-uri", true); let position = Arc::new(RwLock::new(None)); @@ -258,8 +258,7 @@ impl Player for GStreamer { let (status_tx, status_rx) = unbounded::(); let position_update = Arc::clone(&position); - let _playback_monitor = - std::thread::spawn(|| playback_monitor(playbin_arc, status_rx, playback_tx, position_update)); + std::thread::spawn(|| playback_monitor(playbin_arc, status_rx, playback_tx, position_update)); // Set up the thread to monitor bus messages let playbin_bus_ctrl = Arc::clone(&playbin); @@ -477,7 +476,7 @@ fn playback_monitor( let mut sent_atf = false; loop { // Check for new messages to decide how to proceed - if let Ok(result) = status_rx.recv_timeout(std::time::Duration::from_millis(10)) { + if let Ok(result) = status_rx.recv_timeout(std::time::Duration::from_millis(50)) { stats = result } @@ -490,8 +489,9 @@ fn playback_monitor( match stats { PlaybackInfo::Playing{start, end} if pos_temp.is_some() => { // Check if the current playback position is close to the end - let finish_point = end - Duration::milliseconds(250); + let finish_point = end - Duration::milliseconds(2000); if pos_temp.unwrap().num_microseconds() >= end.num_microseconds() { + println!("MONITOR: End of stream"); let _ = playback_tx.try_send(PlayerCommand::EndOfStream); playbin .write() @@ -500,7 +500,9 @@ fn playback_monitor( .expect("Unable to set the pipeline state"); sent_atf = false } else if pos_temp.unwrap().num_microseconds() >= finish_point.num_microseconds() - && !sent_atf { + && !sent_atf + { + println!("MONITOR: About to finish"); let _ = playback_tx.try_send(PlayerCommand::AboutToFinish); sent_atf = true; } @@ -510,6 +512,7 @@ fn playback_monitor( pos_temp = Some(pos_temp.unwrap() - start) }, PlaybackInfo::Finished => { + println!("MONITOR: Shutting down"); *position.write().unwrap() = None; break }, diff --git a/src/music_storage/library.rs b/src/music_storage/library.rs index 1dd63b5..a2fed42 100644 --- a/src/music_storage/library.rs +++ b/src/music_storage/library.rs @@ -283,8 +283,8 @@ impl Song { } // Find images around the music file that can be used - let mut found_images = find_images(target_file.as_ref()).unwrap(); - album_art.append(&mut found_images); + let found_images = find_images(target_file.as_ref()).unwrap(); + album_art.extend_from_slice(&found_images); // Get the format as a string let format: Option = match FileFormat::from_file(target_file) { @@ -624,8 +624,6 @@ impl Album<'_> { } } -const BLOCKED_EXTENSIONS: [&str; 4] = ["vob", "log", "txt", "sf2"]; - #[derive(Debug, Serialize, Deserialize)] pub struct MusicLibrary { pub name: String, @@ -636,6 +634,8 @@ pub struct MusicLibrary { } impl MusicLibrary { + const BLOCKED_EXTENSIONS: &'static [&'static str] = &["vob", "log", "txt", "sf2"]; + /// Create a new library from a name and [Uuid] fn new(name: String, uuid: Uuid) -> Self { MusicLibrary { @@ -654,7 +654,7 @@ impl MusicLibrary { /// the [MusicLibrary] Vec pub fn init(config: Arc>, uuid: Uuid) -> Result> { let global_config = &*config.read().unwrap(); - let path = global_config.libraries.get_library(&uuid)?.path; + let path = global_config.libraries.get_library(&uuid)?.path.clone(); let library: MusicLibrary = match path.exists() { true => read_file(path)?, @@ -671,7 +671,8 @@ impl MusicLibrary { } //#[cfg(debug_assertions)] // We probably wouldn't want to use this for real, but maybe it would have some utility? - pub fn from_path(path: PathBuf) -> Result> { + pub fn from_path>(path: &P) -> Result> { + let path: PathBuf = path.as_ref().to_path_buf(); let library: MusicLibrary = match path.exists() { true => read_file(path)?, false => { @@ -684,8 +685,8 @@ impl MusicLibrary { } /// Serializes the database out to the file specified in the config - pub fn save(&self, config: Config) -> Result<(), Box> { - let path = config.libraries.get_library(&self.uuid)?.path; + pub fn save(&self, config: Arc>) -> Result<(), Box> { + let path = config.read().unwrap().libraries.get_library(&self.uuid)?.path.clone(); match path.try_exists() { Ok(_) => write_file(self, path)?, Err(error) => return Err(error.into()), @@ -715,7 +716,7 @@ impl MusicLibrary { for location in &track.location { //TODO: check that this works if path == location { - return std::ops::ControlFlow::Break((track, i)); + return Break((track, i)); } } Continue(()) @@ -765,7 +766,7 @@ impl MusicLibrary { } /// Finds all the audio files within a specified folder - pub fn scan_folder(&mut self, target_path: &str) -> Result> { + pub fn scan_folder>(&mut self, target_path: &P) -> Result> { let mut total = 0; let mut errors = 0; for target_file in WalkDir::new(target_path) @@ -803,27 +804,29 @@ impl MusicLibrary { // If it's a normal file, add it to the database // if it's a cuesheet, do a bunch of fancy stuff if (format.kind() == Kind::Audio || format.kind() == Kind::Video) - && !BLOCKED_EXTENSIONS.contains(&extension.as_str()) + && !Self::BLOCKED_EXTENSIONS.contains(&extension.as_str()) { match self.add_file(target_file.path()) { Ok(_) => total += 1, Err(_error) => { errors += 1; - //println!("{}, {:?}: {}", format, target_file.file_name(), _error) + println!("{:?}: {}", target_file.file_name(), _error) } // TODO: Handle more of these errors }; } else if extension == "cue" { total += match self.add_cuesheet(target_file.path()) { Ok(added) => added, - Err(error) => { + Err(_error) => { errors += 1; - //println!("{}", error); + println!("{:?}: {}", target_file.file_name(), _error); 0 } } } } + println!("Total scanning errors: {}", errors); + Ok(total) }