Clamp volume in engine
This commit is contained in:
parent
d236d108e8
commit
d9782a7390
|
|
@ -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?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue