]> Untitled Git - mpdstream/commitdiff
Test retry autostart next
authorHugo Villeneuve <hvilleneuve@dimonoff.com>
Thu, 2 Apr 2026 15:20:33 +0000 (11:20 -0400)
committerHugo Villeneuve <hvilleneuve@dimonoff.com>
Thu, 2 Apr 2026 15:20:33 +0000 (11:20 -0400)
Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
src/main.c

index c65358c483445c07b0da9d4f385432063c18859d..7ea77c22ccc8a208893794228a21774c83d4ec25 100644 (file)
@@ -31,6 +31,7 @@ static enum mpd_state last_state;
 static struct mpd_connection *mpdc;
 static bool is_stream;
 static int song_id;
+static int abnormal_stop;
 
 int mpd_check_for_error(void)
 {
@@ -152,7 +153,6 @@ int mpdstream_monitor_status(void)
 {
        struct mpd_status *status;
        enum mpd_state state;
-       int abnormal_stop;
 
        status = mpd_run_status(mpdc);
        if (status == NULL)
@@ -166,17 +166,15 @@ int mpdstream_monitor_status(void)
        case MPD_STATE_PLAY:
                log_info("Playback started\n");
                is_stream = is_stream_uri(status);
+               abnormal_stop = false;
                break;
        case MPD_STATE_PAUSE:
                log_info("Playback paused\n"); /* No action */
+               abnormal_stop = false;
                break;
        case MPD_STATE_STOP:
                log_info("Playback stopped\n");
                abnormal_stop = mpd_check_abnormal_stop(status);
-               if (abnormal_stop) {
-                       log_warn("Auto restart stream after error...\n");
-                       (void) mpd_replay(song_id);
-               }
                break;
        default:
                log_warn("Playback unknown state\n");
@@ -200,6 +198,11 @@ void mpdstream_monitor_loop(struct pollfd *pfd)
 
                (void) mpdstream_monitor_status();
 
+               if (abnormal_stop) {
+                       log_warn("Auto restart stream after error...\n");
+                       (void) mpd_replay(song_id);
+               }
+
                /*
                 * Configure idle event(s):
                 *   MPD_IDLE_PLAYER: state has changed: play, stop, pause, seek, etc
@@ -292,6 +295,7 @@ main(int argc, char **argv)
                is_stream = false;
                song_id = -1;
                last_state = -1;
+               abnormal_stop = false;
 
                log_debug("Waiting for events...\n");