extern crate std; pub struct Player { player: Option, } impl Player { pub fn play(&mut self) -> Result<(), &'static str> { match std::process::Command::new("mpv").arg("https://www.youtube.com/watch?v=3bNITQR4Uso").arg("--no-video").stdin(std::process::Stdio::null()).spawn() { Ok(child) => { self.player = Some(child); Ok(()) } Err(_) => Err("Couldn't use mpv to play music") } } } impl Drop for Player { fn drop(&mut self) { match self.player { Some(ref mut x) => { let _ = x.kill(); } None => { } } } } pub fn new() -> Player { Player { player: None } }