Skip to content

Commit 98cd75f

Browse files
committed
feat(mpris): Add set_volume handler
1 parent 5036953 commit 98cd75f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/mpris_event_handler.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -626,11 +626,17 @@ impl MprisPlayerService {
626626
}
627627

628628
#[zbus(property)]
629-
async fn set_volume(&mut self, _value: Volume) -> zbus::fdo::Result<()> {
630-
// TODO: implement
631-
Err(zbus::fdo::Error::NotSupported(
632-
"Player control not implemented".to_owned(),
633-
))
629+
async fn set_volume(&mut self, value: Volume) -> zbus::fdo::Result<()> {
630+
if let Some(spirc) = &self.spirc {
631+
// As of rust 1.45, cast is guaranteed to round to 0 and saturate.
632+
// MPRIS volume is expected to range between 0 and 1, see
633+
// https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Simple-Type:Volume
634+
let mapped_volume = (value * (u16::MAX as f64)).round() as u16;
635+
spirc
636+
.set_volume(mapped_volume)
637+
.map_err(|err| zbus::fdo::Error::Failed(format!("{err}")))?;
638+
}
639+
Ok(())
634640
}
635641

636642
// The current track position in microseconds, between 0 and the 'mpris:length' metadata entry

0 commit comments

Comments
 (0)