mirror of
https://github.com/Dangoware/dango-music-player.git
synced 2025-04-19 10:02:53 -05:00
Moved location of uri.exists()
to in Player
This commit is contained in:
parent
c6b561c7af
commit
d2822bbb37
2 changed files with 14 additions and 7 deletions
|
@ -249,9 +249,7 @@ impl Controller {
|
|||
in_thread.send(QueueResponse::Default).unwrap();
|
||||
},
|
||||
Enqueue(uri) => {
|
||||
if uri.exists().unwrap() {
|
||||
queue.player.enqueue_next(&uri);
|
||||
}
|
||||
queue.player.enqueue_next(&uri).unwrap();
|
||||
|
||||
// in_thread.send(QueueResponse::Default).unwrap();
|
||||
}
|
||||
|
|
|
@ -68,6 +68,8 @@ pub enum PlayerError {
|
|||
Factory(#[from] glib::BoolError),
|
||||
#[error("could not change playback state")]
|
||||
StateChange(#[from] gst::StateChangeError),
|
||||
#[error("the file or source is not found")]
|
||||
NotFound,
|
||||
#[error("failed to build gstreamer item")]
|
||||
Build,
|
||||
#[error("poison error")]
|
||||
|
@ -257,12 +259,17 @@ impl Player {
|
|||
&self.source
|
||||
}
|
||||
|
||||
pub fn enqueue_next(&mut self, next_track: &URI) {
|
||||
self.set_source(next_track);
|
||||
pub fn enqueue_next(&mut self, next_track: &URI) -> Result<(), PlayerError> {
|
||||
self.set_source(next_track)
|
||||
}
|
||||
|
||||
/// Set the playback URI
|
||||
fn set_source(&mut self, source: &URI) {
|
||||
fn set_source(&mut self, source: &URI) -> Result<(), PlayerError> {
|
||||
if !source.exists().is_ok_and(|x| x) {
|
||||
// If the source doesn't exist, gstreamer will crash!
|
||||
return Err(PlayerError::NotFound)
|
||||
}
|
||||
|
||||
// Make sure the playback tracker knows the stuff is stopped
|
||||
self.playback_tx.send(PlaybackStats::Switching).unwrap();
|
||||
|
||||
|
@ -290,7 +297,7 @@ impl Player {
|
|||
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;
|
||||
return Ok(());
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_millis(1));
|
||||
}
|
||||
|
@ -321,6 +328,8 @@ impl Player {
|
|||
}).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Gets a mutable reference to the playbin element
|
||||
|
|
Loading…
Reference in a new issue