mirror of
https://github.com/talwat/lowfi
synced 2024-12-26 19:21:54 +00:00
feat: also clamp volume in mpris
This commit is contained in:
parent
41bba2d6e4
commit
cc73fa5a37
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1312,7 +1312,7 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lowfi"
|
name = "lowfi"
|
||||||
version = "1.4.0"
|
version = "1.4.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"Inflector",
|
"Inflector",
|
||||||
"arc-swap",
|
"arc-swap",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "lowfi"
|
name = "lowfi"
|
||||||
version = "1.4.0"
|
version = "1.4.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "An extremely simple lofi player."
|
description = "An extremely simple lofi player."
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
@ -137,6 +137,11 @@ impl Player {
|
|||||||
self.current.load().is_some()
|
self.current.load().is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the volume of the sink, and also clamps the value to avoid negative/over 100% values.
|
||||||
|
pub fn set_volume(&self, volume: f32) {
|
||||||
|
self.sink.set_volume(volume.clamp(0.0, 1.0))
|
||||||
|
}
|
||||||
|
|
||||||
/// Initializes the entire player, including audio devices & sink.
|
/// Initializes the entire player, including audio devices & sink.
|
||||||
///
|
///
|
||||||
/// `silent` can control whether alsa's output should be redirected,
|
/// `silent` can control whether alsa's output should be redirected,
|
||||||
@ -256,7 +261,7 @@ impl Player {
|
|||||||
Downloader::notify(&itx).await?;
|
Downloader::notify(&itx).await?;
|
||||||
|
|
||||||
// Set the initial sink volume to the one specified.
|
// Set the initial sink volume to the one specified.
|
||||||
player.sink.set_volume(properties.volume as f32 / 100.0);
|
player.set_volume(properties.volume as f32 / 100.0);
|
||||||
|
|
||||||
// Whether the last signal was a `NewSong`.
|
// Whether the last signal was a `NewSong`.
|
||||||
// This is helpful, since we only want to autoplay
|
// This is helpful, since we only want to autoplay
|
||||||
@ -308,9 +313,7 @@ impl Player {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Messages::ChangeVolume(change) => {
|
Messages::ChangeVolume(change) => {
|
||||||
player
|
player.set_volume(player.sink.volume() + change);
|
||||||
.sink
|
|
||||||
.set_volume((player.sink.volume() + change).clamp(0.0, 1.0));
|
|
||||||
}
|
}
|
||||||
// This basically just continues, but more importantly, it'll re-evaluate
|
// This basically just continues, but more importantly, it'll re-evaluate
|
||||||
// the select macro at the beginning of the loop.
|
// the select macro at the beginning of the loop.
|
||||||
|
@ -169,7 +169,7 @@ impl PlayerInterface for Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn set_volume(&self, volume: Volume) -> Result<()> {
|
async fn set_volume(&self, volume: Volume) -> Result<()> {
|
||||||
self.player.sink.set_volume(volume as f32);
|
self.player.set_volume(volume as f32);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user