commit a973348dc123448b654e5e3786a8d2d2ad9c91bf
parent 84e97354c3e6631ee825ff27089726f5b39ba334
Author: mtmn <miro@haravara.org>
Date: Sat, 8 Aug 2026 21:42:24 +0200
only print mpd_now_playing when actually playing
Diffstat:
2 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/mpd/mpd_now_playing.c b/mpd/mpd_now_playing.c
@@ -78,6 +78,10 @@ static bool emit_snapshot(struct mpd_connection *connection, bool json) {
return false;
}
enum mpd_state state = mpd_status_get_state(status);
+ if (state != MPD_STATE_PLAY) {
+ mpd_status_free(status);
+ return true;
+ }
int position = mpd_status_get_song_pos(status);
int song_id = mpd_status_get_song_id(status);
unsigned elapsed_ms = mpd_status_get_elapsed_ms(status);
diff --git a/mpd/tests/test_mpd_tools.py b/mpd/tests/test_mpd_tools.py
@@ -466,6 +466,16 @@ class MPDToolsTest(unittest.TestCase):
self.assertEqual(value["elapsed_seconds"], 12.5)
self.assertEqual(value["song_id"], 1)
+ def test_now_playing_is_silent_when_paused_or_stopped(self):
+ for state in ("pause", "stop"):
+ with self.subTest(state=state):
+ self.seed_queue(["track.ogg"], current=0, state=state)
+ for arguments in ((), ("--json",)):
+ with self.subTest(arguments=arguments):
+ result = self.run_tool("mpd_now_playing", *arguments)
+ self.assertEqual(result.returncode, 0, result.stderr)
+ self.assertEqual(result.stdout, "")
+
def test_explicit_config_helper_overrides_connection_environment(self):
self.seed_queue(["helper.ogg"], current=0, state="play")
with tempfile.TemporaryDirectory() as directory: