fix(mpd) Support relative seek percentages
This commit is contained in:
parent
20934b9316
commit
c7b6554668
@ -209,6 +209,10 @@ namespace mpd
|
|||||||
auto status = this->get_status();
|
auto status = this->get_status();
|
||||||
if (status->total_time == 0)
|
if (status->total_time == 0)
|
||||||
return;
|
return;
|
||||||
|
if (percentage < 0)
|
||||||
|
percentage = 0;
|
||||||
|
else if (percentage > 100)
|
||||||
|
percentage = 100;
|
||||||
int pos = float(status->total_time) * percentage / 100.0f + 0.5f;
|
int pos = float(status->total_time) * percentage / 100.0f + 0.5f;
|
||||||
this->check_prerequisites_commands_list();
|
this->check_prerequisites_commands_list();
|
||||||
mpd_run_seek_id(this->connection.get(), status->song_id, pos);
|
mpd_run_seek_id(this->connection.get(), status->song_id, pos);
|
||||||
|
@ -290,9 +290,19 @@ bool MpdModule::handle_command(const std::string& cmd)
|
|||||||
mpd->random(true);
|
mpd->random(true);
|
||||||
else if (cmd.find(EVENT_SEEK) == 0) {
|
else if (cmd.find(EVENT_SEEK) == 0) {
|
||||||
auto s = cmd.substr(std::strlen(EVENT_SEEK));
|
auto s = cmd.substr(std::strlen(EVENT_SEEK));
|
||||||
|
int perc = 0;
|
||||||
if (s.empty())
|
if (s.empty())
|
||||||
return false;
|
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
|
} else
|
||||||
return false;
|
return false;
|
||||||
} catch (mpd::Exception &e) {
|
} catch (mpd::Exception &e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user