Fix wrong songs playing when queue is not empty
if we are playing a song which is in the middle of somewhere in queue. it will play the wrong song, since the index points to wrong song
This commit is contained in:
parent
bf11d5967f
commit
3f6b2bfefd
|
|
@ -12,7 +12,6 @@ pub struct App {
|
||||||
/// check if app is running
|
/// check if app is running
|
||||||
pub running: bool,
|
pub running: bool,
|
||||||
pub conn: Connection,
|
pub conn: Connection,
|
||||||
pub play_deque: ContentList<String>,
|
|
||||||
pub song_list: ContentList<String>,
|
pub song_list: ContentList<String>,
|
||||||
pub queue_list: ContentList<String>,
|
pub queue_list: ContentList<String>,
|
||||||
pub pl_list: ContentList<String>,
|
pub pl_list: ContentList<String>,
|
||||||
|
|
@ -21,11 +20,11 @@ pub struct App {
|
||||||
impl App {
|
impl App {
|
||||||
pub fn builder(addrs: &str) -> AppResult<Self> {
|
pub fn builder(addrs: &str) -> AppResult<Self> {
|
||||||
let mut conn = Connection::new(addrs).unwrap();
|
let mut conn = Connection::new(addrs).unwrap();
|
||||||
let mut queue = ContentList::new();
|
let mut queue_list = ContentList::new();
|
||||||
let mut pl_list = ContentList::new();
|
let mut pl_list = ContentList::new();
|
||||||
pl_list.list = Self::get_playlist(&mut conn.conn)?;
|
pl_list.list = Self::get_playlist(&mut conn.conn)?;
|
||||||
|
|
||||||
Self::get_queue(&mut conn, &mut queue.list);
|
Self::get_queue(&mut conn, &mut queue_list.list);
|
||||||
|
|
||||||
let mut song_list = ContentList::new();
|
let mut song_list = ContentList::new();
|
||||||
song_list.list = conn.songs_filenames.clone();
|
song_list.list = conn.songs_filenames.clone();
|
||||||
|
|
@ -33,9 +32,8 @@ impl App {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
running: true,
|
running: true,
|
||||||
conn,
|
conn,
|
||||||
play_deque: ContentList::new(),
|
|
||||||
song_list,
|
song_list,
|
||||||
queue_list: ContentList::new(),
|
queue_list,
|
||||||
pl_list,
|
pl_list,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,10 +70,11 @@ impl Connection {
|
||||||
self.conn.play().unwrap();
|
self.conn.play().unwrap();
|
||||||
} else {
|
} else {
|
||||||
self.conn.push(song)?;
|
self.conn.push(song)?;
|
||||||
|
let len: u32 = (self.conn.queue().unwrap().len() - 1).try_into().unwrap();
|
||||||
|
self.conn.switch(len)?;
|
||||||
if self.conn.status()?.state == State::Stop {
|
if self.conn.status()?.state == State::Stop {
|
||||||
self.conn.play()?;
|
self.conn.play()?;
|
||||||
}
|
}
|
||||||
self.conn.next().unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,9 @@ impl<T> ContentList<T> {
|
||||||
|
|
||||||
/// Go to previous item in list
|
/// Go to previous item in list
|
||||||
pub fn prev(&mut self) {
|
pub fn prev(&mut self) {
|
||||||
if self.index != 0 {
|
if self.index == 0 {
|
||||||
|
self.index = self.list.len() - 1;
|
||||||
|
} else {
|
||||||
self.index -= 1;
|
self.index -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in New Issue