Check if audio is busy in separate function
This commit is contained in:
24
src/main.rs
24
src/main.rs
@@ -64,15 +64,10 @@ async fn main() {
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
rx.filter_map(|()| async {
|
rx.filter_map(|()| async {
|
||||||
AUDIO_CHILD.with(|cell| {
|
if audio_busy() {
|
||||||
if let Some(ref mut audio_child) = *cell.borrow_mut() {
|
debug!("doorbell still ringing, ignoring press");
|
||||||
if let Ok(None) = audio_child.try_wait() {
|
return None;
|
||||||
debug!("doorbell still ringing, ignoring press");
|
}
|
||||||
return None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(())
|
|
||||||
})?;
|
|
||||||
debug!("Playing doorbell chime");
|
debug!("Playing doorbell chime");
|
||||||
match process::Command::new("mplayer")
|
match process::Command::new("mplayer")
|
||||||
.arg("static/outdoor.mp3")
|
.arg("static/outdoor.mp3")
|
||||||
@@ -92,3 +87,14 @@ async fn main() {
|
|||||||
let routes = root.or(events);
|
let routes = root.or(events);
|
||||||
warp::serve(routes).run(([0, 0, 0, 0], 8060)).await;
|
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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user