File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments