diff --git a/src/main.rs b/src/main.rs index b00ba8d..8b8ef4a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,17 +49,8 @@ async fn main() { let (tx, rx) = mpsc::channel(1); events_clients.lock().unwrap().push(tx); let pushes = rx.for_each(|()| { - if !audio_busy() { - trace!("Playing doorbell chime"); - match process::Command::new("mplayer") - .arg(OUTDOOR_CHIME_FILE) - .stdout(process::Stdio::null()) - .stderr(process::Stdio::null()) - .spawn() { - Ok(child) => { AUDIO_CHILD.with(|cell| cell.replace(Some(child))); }, - Err(err) => error!("Error playing outdoor chime: {}", err) - }; - } else { debug!("doorbell still ringing, not playing new chime"); } + if !audio_busy() { play_chime() } + else { debug!("doorbell still ringing, not playing new chime"); } futures_util::future::ready(()) }); @@ -118,3 +109,15 @@ fn audio_busy() -> bool { false }) } + +fn play_chime() { + trace!("Playing doorbell chime"); + match process::Command::new("mplayer") + .arg(OUTDOOR_CHIME_FILE) + .stdout(process::Stdio::null()) + .stderr(process::Stdio::null()) + .spawn() { + Ok(child) => { AUDIO_CHILD.with(|cell| cell.replace(Some(child))); }, + Err(err) => error!("Error playing outdoor chime: {}", err) + }; +}