From 932471218aab67f188f1c774d7858a4c137f36cc Mon Sep 17 00:00:00 2001 From: Erica Z Date: Sat, 16 Nov 2024 14:42:28 +0100 Subject: [PATCH] some mpris work --- src/mpris/player.rs | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/mpris/player.rs b/src/mpris/player.rs index a56d741..05790ab 100644 --- a/src/mpris/player.rs +++ b/src/mpris/player.rs @@ -242,35 +242,46 @@ impl Player { #[zbus::interface(name = "org.mpris.MediaPlayer2.Player")] impl Player { fn next(&self) -> zbus::fdo::Result<()> { - Err(zbus::fdo::Error::NotSupported("not implemented".into())) + self.window().playlist_next(); + Ok(()) } fn previous(&self) -> zbus::fdo::Result<()> { - Err(zbus::fdo::Error::NotSupported("not implemented".into())) + self.window().playlist_prev(); + Ok(()) } fn pause(&self) -> zbus::fdo::Result<()> { - Err(zbus::fdo::Error::NotSupported("not implemented".into())) + self.window().set_pause(true); + Ok(()) } fn play_pause(&self) -> zbus::fdo::Result<()> { - Err(zbus::fdo::Error::NotSupported("not implemented".into())) + self.window().set_pause(!self.window().pause()); + Ok(()) } fn stop(&self) -> zbus::fdo::Result<()> { - Err(zbus::fdo::Error::NotSupported("not implemented".into())) + self.window().set_pause(true); + self.window().set_time_pos(0.0); + Ok(()) } fn play(&self) -> zbus::fdo::Result<()> { - Err(zbus::fdo::Error::NotSupported("not implemented".into())) + self.window().set_pause(false); + Ok(()) } - fn seek(&self, _offset: i64) -> zbus::fdo::Result<()> { - Err(zbus::fdo::Error::NotSupported("not implemented".into())) + fn seek(&self, offset: i64) -> zbus::fdo::Result<()> { + self.window().seek(offset as f64 / MICROSECONDS); + Ok(()) } - fn set_position(&self, _track_id: ObjectPath<'_>, _position: i64) -> zbus::fdo::Result<()> { - Err(zbus::fdo::Error::NotSupported("not implemented".into())) + fn set_position(&self, track_id: ObjectPath<'_>, position: i64) -> zbus::fdo::Result<()> { + if Some(track_id) == self.metadata.track_id.as_ref().map(|x| x.as_ref()) { + self.window().set_time_pos(position as f64 / MICROSECONDS); + } + Ok(()) } fn open_uri(&self, _s: String) -> zbus::fdo::Result<()> {