From 3f6b2bfefd54a53e675e0cffc98b704d3b8ad244 Mon Sep 17 00:00:00 2001 From: krolxon Date: Wed, 24 Apr 2024 12:52:32 +0530 Subject: [PATCH] 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 --- src/app.rs | 8 +++----- src/connection.rs | 3 ++- src/list.rs | 4 +++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/app.rs b/src/app.rs index 1e0e8e2..dddcd75 100755 --- a/src/app.rs +++ b/src/app.rs @@ -12,7 +12,6 @@ pub struct App { /// check if app is running pub running: bool, pub conn: Connection, - pub play_deque: ContentList, pub song_list: ContentList, pub queue_list: ContentList, pub pl_list: ContentList, @@ -21,11 +20,11 @@ pub struct App { impl App { pub fn builder(addrs: &str) -> AppResult { let mut conn = Connection::new(addrs).unwrap(); - let mut queue = ContentList::new(); + let mut queue_list = ContentList::new(); let mut pl_list = ContentList::new(); 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(); song_list.list = conn.songs_filenames.clone(); @@ -33,9 +32,8 @@ impl App { Ok(Self { running: true, conn, - play_deque: ContentList::new(), song_list, - queue_list: ContentList::new(), + queue_list, pl_list, }) } diff --git a/src/connection.rs b/src/connection.rs index e0e788d..fa8cc78 100755 --- a/src/connection.rs +++ b/src/connection.rs @@ -70,10 +70,11 @@ impl Connection { self.conn.play().unwrap(); } else { 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 { self.conn.play()?; } - self.conn.next().unwrap(); } Ok(()) diff --git a/src/list.rs b/src/list.rs index d5d5524..452907d 100755 --- a/src/list.rs +++ b/src/list.rs @@ -27,7 +27,9 @@ impl ContentList { /// Go to previous item in list pub fn prev(&mut self) { - if self.index != 0 { + if self.index == 0 { + self.index = self.list.len() - 1; + } else { self.index -= 1; } }