fix(mpd) Support relative seek percentages

This commit is contained in:
Michael Carlberg 2016-05-20 05:34:07 +02:00
parent 20934b9316
commit c7b6554668
2 changed files with 15 additions and 1 deletions

View File

@ -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);

View File

@ -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) {