Mercurial > beefweb_mpris
diff src/player.rs @ 2:594c0f9d7972
errr
| author | Paper <paper@tflc.us> |
|---|---|
| date | Sat, 04 Apr 2026 16:04:31 -0400 |
| parents | a5ee18c79a04 |
| children | 18f743c980fa |
line wrap: on
line diff
--- a/src/player.rs Sat Apr 04 12:34:46 2026 -0400 +++ b/src/player.rs Sat Apr 04 16:04:31 2026 -0400 @@ -23,7 +23,7 @@ use zbus::fdo; use zbus::Result; use std::collections::HashMap; -use std::io::Write; +//use std::io::Write; use std::cell::RefCell; /* teehee */ @@ -237,34 +237,35 @@ _ => (), }; - return match p.unwrap().playback_state.as_str() { - "playing" => Ok(mpris_server::PlaybackStatus::Playing), - "stopped" => Ok(mpris_server::PlaybackStatus::Stopped), - "paused" => Ok(mpris_server::PlaybackStatus::Paused), - _ => Err(fdo::Error::Failed("deez nuts".to_string())), + return match p.unwrap().playback_state { + beefweb::PlaybackState::PLAYING => Ok(mpris_server::PlaybackStatus::Playing), + beefweb::PlaybackState::STOPPED => Ok(mpris_server::PlaybackStatus::Stopped), + beefweb::PlaybackState::PAUSED => Ok(mpris_server::PlaybackStatus::Paused), }; } async fn loop_status(&self) -> fdo::Result<mpris_server::LoopStatus> { + /* TODO -- we can do this w/ self.bw.playback_order() */ return Ok(mpris_server::LoopStatus::None); } async fn set_loop_status(&self, loop_status: mpris_server::LoopStatus) -> Result<()> { + /* TODO -- implement self.bw.set_playback_order() */ return Ok(()); } async fn shuffle(&self) -> fdo::Result<bool> { - /* TODO */ + /* TODO -- we can do this w/ self.bw.playback_order() */ println!("Shuffle"); return Ok(false); } async fn set_shuffle(&self, shuffle: bool) -> Result<()> { - /* TODO */ + /* TODO -- implement self.bw.set_playback_order() */ println!("SetShuffle({shuffle})"); return Ok(()); } @@ -315,11 +316,33 @@ async fn volume(&self) -> fdo::Result<mpris_server::Volume> { - return Ok(mpris_server::Volume::default()); + let vr = self.bw.volume().await; + + match vr { + Err(_) => return Err(fdo::Error::Failed("uhoh".to_string())), + _ => (), + } + + let v = vr.unwrap(); + + /* dB -> linear */ + return Ok(match v.r#type { + beefweb::VolumeType::DB => 10.0_f64.powf(v.value / 20.0), + beefweb::VolumeType::LINEAR => v.value, + beefweb::VolumeType::UPDOWN => /* ??? */ v.value, + }); } async fn set_volume(&self, volume: mpris_server::Volume) -> Result<()> { + /* linear -> dB */ + let v = 20.0 * volume.log10(); + + match self.bw.set_volume(v).await { + Err(_) => return Err(zbus::Error::Failure("uhoh".to_string())), + _ => (), + } + return Ok(()); }
