blob: 90cd2760a29542a4c0bdb23f768bbe8f15137bf4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
extern crate std;
pub struct Player {
player: Option<std::process::Child>,
}
impl Player {
pub fn play(&mut self) -> Result<(), &'static str> {
match std::process::Command::new("mpv").arg("https://www.youtube.com/watch?v=TdWd7Znz00Q").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 }
}
|