rmptuibc0348e
song insertion state check
+4 −3
1 file changed
- M src/connection.rs +4 −3
| @@ -1,7 +1,6 @@ | |||
| 1 | 1 | use mpd::song::Song; | |
| 2 | − | use mpd::Client; | |
| 2 | + | use mpd::{Client, State}; | |
| 3 | 3 | use simple_dmenu::dmenu; | |
| 4 | − | use std::process::Command; | |
| 5 | 4 | ||
| 6 | 5 | pub struct Connection { | |
| 7 | 6 | pub conn: Client, | |
| @@ -37,12 +36,14 @@ impl Connection { | |||
| 37 | 36 | } | |
| 38 | 37 | ||
| 39 | 38 | fn push(&mut self, song: &Song) { | |
| 40 | − | self.conn.push(song).unwrap(); | |
| 41 | 39 | if self.conn.queue().unwrap().is_empty() { | |
| 42 | 40 | self.conn.push(song).unwrap(); | |
| 43 | 41 | self.conn.play().unwrap(); | |
| 44 | 42 | } else { | |
| 45 | 43 | self.conn.push(song).unwrap(); | |
| 44 | + | if self.conn.status().unwrap().state == State::Stop { | |
| 45 | + | self.conn.play().unwrap(); | |
| 46 | + | } | |
| 46 | 47 | self.conn.next().unwrap(); | |
| 47 | 48 | } | |
| 48 | 49 | } | |