Merge pull request #203 from chme/mpdseek

[mpd] Fix seek command
This commit is contained in:
ejurgensen 2015-12-12 11:14:10 +01:00
commit cb9034bee7

View File

@ -835,15 +835,11 @@ mpd_command_status(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
"time: %d:%d\n" "time: %d:%d\n"
"elapsed: %#.3f\n" "elapsed: %#.3f\n"
"bitrate: 128\n" "bitrate: 128\n"
"audio: 44100:16:2\n" "audio: 44100:16:2\n",
"nextsong: %d\n"
"nextsongid: %d\n",
status.pos_pl, status.pos_pl,
status.item_id, status.item_id,
(status.pos_ms / 1000), (status.len_ms / 1000), (status.pos_ms / 1000), (status.len_ms / 1000),
(status.pos_ms / 1000.0), (status.pos_ms / 1000.0));
status.next_pos_pl,
status.next_item_id);
} }
if (filescanner_scanning()) if (filescanner_scanning())
@ -857,7 +853,7 @@ mpd_command_status(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
"nextsong: %d\n" "nextsong: %d\n"
"nextsongid: %d\n", "nextsongid: %d\n",
status.next_pos_pl, status.next_pos_pl,
status.next_id); status.next_item_id);
} }
return 0; return 0;
@ -1356,6 +1352,7 @@ mpd_command_previous(struct evbuffer *evbuf, int argc, char **argv, char **errms
static int static int
mpd_command_seek(struct evbuffer *evbuf, int argc, char **argv, char **errmsg) mpd_command_seek(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
{ {
struct player_status status;
uint32_t songpos; uint32_t songpos;
float seek_target_sec; float seek_target_sec;
int seek_target_msec; int seek_target_msec;
@ -1363,7 +1360,7 @@ mpd_command_seek(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
if (argc < 3) if (argc < 3)
{ {
ret = asprintf(errmsg, "Missing argument for command 'seekcur'"); ret = asprintf(errmsg, "Missing argument for command 'seek'");
if (ret < 0) if (ret < 0)
DPRINTF(E_LOG, L_MPD, "Out of memory\n"); DPRINTF(E_LOG, L_MPD, "Out of memory\n");
return ACK_ERROR_ARG; return ACK_ERROR_ARG;
@ -1379,7 +1376,8 @@ mpd_command_seek(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
} }
//TODO Allow seeking in songs not currently playing //TODO Allow seeking in songs not currently playing
if (songpos != 0) player_get_status(&status);
if (status.pos_pl != songpos)
{ {
ret = asprintf(errmsg, "Given song is not the current playing one, seeking is not supported"); ret = asprintf(errmsg, "Given song is not the current playing one, seeking is not supported");
if (ret < 0) if (ret < 0)