From 21e55a4144a8bc1183bc019894042c5a299be110 Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Fri, 17 Apr 2020 14:09:10 +0200
Subject: [PATCH] Correct playid command

---
 src/commands.c       | 10 ++++++++--
 src/database/queue.c |  2 +-
 src/net/listen.c     |  2 ++
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/commands.c b/src/commands.c
index 1604dbbe..b9f6a8e8 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -202,6 +202,7 @@ __play_that_file(sqlite3 *db, struct lkt_win *win, int pos)
         goto error;
     }
 
+    return true;
 error:
     return false;
 }
@@ -238,7 +239,7 @@ command_play(sqlite3 *db, struct lkt_win *win, char *args[LKT_MESSAGE_ARGS_MAX],
     if (win->window)
         win->close(win);
 
-    if (!win->new (win)) {
+    if (!win->new(win)) {
         fprintf(stderr, " ! command_play: command failed because of null mpv ctx\n");
         goto error;
     }
@@ -279,7 +280,12 @@ command_playid(sqlite3 *db, struct lkt_win *win, char *args[LKT_MESSAGE_ARGS_MAX
 
     /* Do the work. */
 
-    if (!win->window && !win->new(win))
+    database_queue_stop(db);
+
+    if (win->window)
+        win->close(win);
+
+    if (!win->new(win))
         goto error;
 
     if (!database_queue_seekid(db, (int) id, &pos))
diff --git a/src/database/queue.c b/src/database/queue.c
index 5186795c..ecd45d86 100644
--- a/src/database/queue.c
+++ b/src/database/queue.c
@@ -731,7 +731,7 @@ database_queue_seekid(sqlite3 *db, int id, int *out_pos)
 
     SQLITE_PREPARE(db, stmt, SQL_STMT, error);
     SQLITE_BIND_INT(db, stmt, 1, id, error);
-    if (SQLITE_OK != sqlite3_step(stmt)) {
+    if (SQLITE_ROW != sqlite3_step(stmt)) {
         fprintf(stderr, "database_queue_seekid: Failed: %s\n", sqlite3_errmsg(db));
         goto error;
     }
diff --git a/src/net/listen.c b/src/net/listen.c
index 3ec2fdf1..e2b7dbee 100644
--- a/src/net/listen.c
+++ b/src/net/listen.c
@@ -202,6 +202,8 @@ handle_simple_command(struct lkt_state *srv, size_t c, struct lkt_command cmd)
         else if (!strcmp(cmd.name, "play"))
             err = ! (command_stop(srv->db, &srv->win, &srv->mpd_idle_events)
                      && command_play(srv->db, &srv->win, cmd.args, &srv->mpd_idle_events));
+        else if (!strcmp(cmd.name, "playid"))
+            err = ! command_playid(srv->db, &srv->win, cmd.args, &srv->mpd_idle_events);
         else if (!strcmp(cmd.name, "stop"))
             err = !command_stop(srv->db, &srv->win, &srv->mpd_idle_events);
         else if (!strcmp(cmd.name, "clear"))
-- 
GitLab