diff --git a/src/interfaces/mpd.cpp b/src/interfaces/mpd.cpp index b62fa3f4..e8e41f29 100644 --- a/src/interfaces/mpd.cpp +++ b/src/interfaces/mpd.cpp @@ -209,6 +209,10 @@ namespace mpd auto status = this->get_status(); if (status->total_time == 0) return; + if (percentage < 0) + percentage = 0; + else if (percentage > 100) + percentage = 100; int pos = float(status->total_time) * percentage / 100.0f + 0.5f; this->check_prerequisites_commands_list(); mpd_run_seek_id(this->connection.get(), status->song_id, pos); diff --git a/src/modules/mpd.cpp b/src/modules/mpd.cpp index 7c6ec117..774834b7 100644 --- a/src/modules/mpd.cpp +++ b/src/modules/mpd.cpp @@ -290,9 +290,19 @@ bool MpdModule::handle_command(const std::string& cmd) mpd->random(true); else if (cmd.find(EVENT_SEEK) == 0) { auto s = cmd.substr(std::strlen(EVENT_SEEK)); + int perc = 0; if (s.empty()) return false; - mpd->seek(std::atoi(s.c_str())); + if (s[0] == '+') { + perc = this->status->get_elapsed_percentage() + + std::atoi(s.substr(1).c_str()); + } else if (s[0] == '-') { + perc = this->status->get_elapsed_percentage() + - std::atoi(s.substr(1).c_str()); + } else { + perc = std::atoi(s.c_str()); + } + mpd->seek(perc); } else return false; } catch (mpd::Exception &e) {