fix: allow any value to set MPRIS volume

This fixes a small inconsistency between the MPRIS implementation and
the specification. The specification allows any number when setting the
volume, which have to be clamped to the effectively allowed range in the
application.
https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:Volume
This commit is contained in:
Thomas Frans
2023-11-29 15:34:02 +01:00
committed by Henrik Friedrichsen
parent e0373890fe
commit 7a9c8f3a5e
2 changed files with 6 additions and 6 deletions

View File

@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Multiple instances interfering with each other's MPRIS implementation
- An unlikely crash when the UNIX IPC socket is removed before `ncspot` is closed
- Guaranteed crash while quiting `ncspot` when using MPRIS
- MPRIS volume not being updated when given numbers smaller than 0 or larger than 1
## [0.13.4] - 2023-07-24

View File

@@ -269,13 +269,12 @@ impl MprisPlayer {
}
#[dbus_interface(property)]
fn set_volume(&self, volume: f64) {
fn set_volume(&self, mut volume: f64) {
log::info!("set volume: {volume}");
if (0.0..=1.0).contains(&volume) {
let vol = (VOLUME_PERCENT as f64) * volume * 100.0;
self.spotify.set_volume(vol as u16);
self.event.trigger();
}
volume = volume.clamp(0.0, 1.0);
let vol = (VOLUME_PERCENT as f64) * volume * 100.0;
self.spotify.set_volume(vol as u16);
self.event.trigger();
}
#[dbus_interface(property)]