Check if audio is busy in separate function

This commit is contained in:
2020-10-28 18:05:21 -07:00
parent e173f58da1
commit 743d5f231c

View File

@@ -64,15 +64,10 @@ async fn main() {
}),
rx.filter_map(|()| async {
AUDIO_CHILD.with(|cell| {
if let Some(ref mut audio_child) = *cell.borrow_mut() {
if let Ok(None) = audio_child.try_wait() {
debug!("doorbell still ringing, ignoring press");
return None;
}
}
Some(())
})?;
if audio_busy() {
debug!("doorbell still ringing, ignoring press");
return None;
}
debug!("Playing doorbell chime");
match process::Command::new("mplayer")
.arg("static/outdoor.mp3")
@@ -92,3 +87,14 @@ async fn main() {
let routes = root.or(events);
warp::serve(routes).run(([0, 0, 0, 0], 8060)).await;
}
fn audio_busy() -> bool {
AUDIO_CHILD.with(|cell| {
if let Some(ref mut audio_child) = *cell.borrow_mut() {
if let Ok(None) = audio_child.try_wait() {
return true;
}
}
false
})
}