Skip to content

Commit

Permalink
fix: allow any value to set MPRIS volume
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ThomasFrans committed Nov 29, 2023
1 parent 0cee99b commit 0082ac1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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

Expand Down
11 changes: 5 additions & 6 deletions src/mpris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 0082ac1

Please sign in to comment.