From fff04a101d22592cf326f6017c589caf6c35f4a7 Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Fri, 18 Dec 2020 10:55:55 +0100
Subject: [PATCH] Can now play the last kara of the queue and stop the playback
 if no next kara is found

---
 src/base/commands.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/base/commands.c b/src/base/commands.c
index 7cf09f54..029eaec9 100644
--- a/src/base/commands.c
+++ b/src/base/commands.c
@@ -183,8 +183,12 @@ command_next(struct lkt_state *srv, char UNUSED *args[LKT_MESSAGE_ARGS_MAX])
 {
     srv->mpd_idle_events |= MPD_IDLE_PLAYER;
     char filepath[PATH_MAX];
-    if (!database_queue_next(srv->db, filepath))
+    if (!database_queue_next(srv->db, filepath)) {
+        LOG_DEBUG("COMMAND",
+                  "Failed to get next, stop the player because we may be at the end of the queue");
+        command_stop(srv, NULL);
         return false;
+    }
     if (MOD_CALL(srv->window_mod, "load", filepath))
         return false;
     else {
@@ -243,7 +247,7 @@ command_play(struct lkt_state *srv, char UNUSED *args[LKT_MESSAGE_ARGS_MAX])
 
     /* If position is after the queue, don't do anything */
     RETURN_UNLESS(database_queue_state(srv->db, &queue_state), "Can't get playback status", false);
-    if (queue_state.length <= pos) {
+    if (queue_state.length < pos) {
         LOG_INFO("COMMAND", "Don't perform play command, queue is empty or position is after queue length");
         return false;
     }
-- 
GitLab