Clamp volume in engine

This commit is contained in:
chmanie 2023-06-08 14:57:17 +02:00
parent d236d108e8
commit d9782a7390
2 changed files with 2 additions and 3 deletions

View File

@ -134,9 +134,8 @@ impl Player {
pub async fn set_volume(&self, volume: f32) -> Result<f32> { pub async fn set_volume(&self, volume: f32) -> Result<f32> {
let (tx, rx) = flume::bounded(1); let (tx, rx) = flume::bounded(1);
let vol = volume.clamp(0.0, 1.1);
self.tx_engine self.tx_engine
.send(PlayerEngineCommand::SetVolume(vol, tx))?; .send(PlayerEngineCommand::SetVolume(volume, tx))?;
rx.recv_async().await? rx.recv_async().await?
} }

View File

@ -210,7 +210,7 @@ impl PlayerEngine {
pub fn set_volume(&mut self, volume: f32) -> Result<f32> { pub fn set_volume(&mut self, volume: f32) -> Result<f32> {
if let Some(sink) = &self.sink { if let Some(sink) = &self.sink {
sink.set_volume(volume); sink.set_volume(volume.clamp(0.0, 1.1));
return Ok(sink.volume()); return Ok(sink.volume());
} }
Err(PlayerEngineError::NotPlaying.into()) Err(PlayerEngineError::NotPlaying.into())