From 8bbd18d9e4da3abad8a7e3c5dd16324d7ae52c3e Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Thu, 2 Apr 2026 11:20:33 -0400 Subject: [PATCH] Test retry autostart Signed-off-by: Hugo Villeneuve --- src/main.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index c65358c..7ea77c2 100644 --- a/src/main.c +++ b/src/main.c @@ -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"); -- 2.47.3