From 7bb168679d21155452baa87a5a28c51895954d5a Mon Sep 17 00:00:00 2001 From: Vasili Karaev Date: Sun, 26 Mar 2017 11:25:32 +0300 Subject: [PATCH] fix(mpd): Check state before calling playback controls #500 --- src/modules/mpd.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/modules/mpd.cpp b/src/modules/mpd.cpp index 894c1a57..bcaacb14 100644 --- a/src/modules/mpd.cpp +++ b/src/modules/mpd.cpp @@ -306,15 +306,19 @@ namespace modules { auto status = mpd->get_status(); - if (cmd == EVENT_PLAY) { + bool is_playing = status->match_state(mpdstate::PLAYING); + bool is_paused = status->match_state(mpdstate::PAUSED); + bool is_stopped = status->match_state(mpdstate::STOPPED); + + if (cmd == EVENT_PLAY && !is_playing) { mpd->play(); - } else if (cmd == EVENT_PAUSE) { - mpd->pause(!(status->match_state(mpdstate::PAUSED))); - } else if (cmd == EVENT_STOP) { + } else if (cmd == EVENT_PAUSE && !is_paused) { + mpd->pause(true); + } else if (cmd == EVENT_STOP && !is_stopped) { mpd->stop(); - } else if (cmd == EVENT_PREV) { + } else if (cmd == EVENT_PREV && !is_stopped) { mpd->prev(); - } else if (cmd == EVENT_NEXT) { + } else if (cmd == EVENT_NEXT && !is_stopped) { mpd->next(); } else if (cmd == EVENT_REPEAT_ONE) { mpd->set_single(!status->single());