Add support for shuffle in DACP playspec request

This commit is contained in:
Julien BLACHE 2010-07-31 12:07:51 +02:00
parent fa0ee0553a
commit 94b4cd2459
2 changed files with 39 additions and 23 deletions

View File

@ -819,6 +819,7 @@ dacp_reply_playspec(struct evhttp_request *req, struct evbuffer *evbuf, char **u
struct player_source *ps; struct player_source *ps;
struct daap_session *s; struct daap_session *s;
const char *param; const char *param;
const char *shuffle;
uint32_t plid; uint32_t plid;
uint32_t id; uint32_t id;
int ret; int ret;
@ -831,6 +832,9 @@ dacp_reply_playspec(struct evhttp_request *req, struct evbuffer *evbuf, char **u
if (!s) if (!s)
return; return;
/* Check for shuffle */
shuffle = evhttp_find_header(query, "dacp.shufflestate");
/* Playlist ID */ /* Playlist ID */
param = evhttp_find_header(query, "container-spec"); param = evhttp_find_header(query, "container-spec");
if (!param) if (!param)
@ -857,33 +861,38 @@ dacp_reply_playspec(struct evhttp_request *req, struct evbuffer *evbuf, char **u
goto out_fail; goto out_fail;
} }
/* Start song ID */ if (!shuffle)
param = evhttp_find_header(query, "container-item-spec");
if (!param)
{ {
DPRINTF(E_LOG, L_DACP, "No container-item-spec in playspec request\n"); /* Start song ID */
param = evhttp_find_header(query, "container-item-spec");
if (!param)
{
DPRINTF(E_LOG, L_DACP, "No container-item-spec in playspec request\n");
goto out_fail; goto out_fail;
}
param = strchr(param, ':');
if (!param)
{
DPRINTF(E_LOG, L_DACP, "Malformed container-item-spec parameter in playspec request\n");
goto out_fail;
}
param++;
ret = safe_hextou32(param, &id);
if (ret < 0)
{
DPRINTF(E_LOG, L_DACP, "Couldn't convert container-item-spec to an integer in playspec (%s)\n", param);
goto out_fail;
}
} }
else
id = 0;
param = strchr(param, ':'); DPRINTF(E_DBG, L_DACP, "Playspec request for playlist %d, start song id %d%s\n", plid, id, (shuffle) ? ", shuffle" : "");
if (!param)
{
DPRINTF(E_LOG, L_DACP, "Malformed container-item-spec parameter in playspec request\n");
goto out_fail;
}
param++;
ret = safe_hextou32(param, &id);
if (ret < 0)
{
DPRINTF(E_LOG, L_DACP, "Couldn't convert container-item-spec to an integer in playspec (%s)\n", param);
goto out_fail;
}
DPRINTF(E_DBG, L_DACP, "Playspec request for playlist %d, start song id %d\n", plid, id);
ps = player_queue_make_pl(plid, &id); ps = player_queue_make_pl(plid, &id);
if (!ps) if (!ps)
@ -903,6 +912,9 @@ dacp_reply_playspec(struct evhttp_request *req, struct evbuffer *evbuf, char **u
player_queue_clear(); player_queue_clear();
player_queue_add(ps); player_queue_add(ps);
if (shuffle)
dacp_propset_shufflestate(shuffle, NULL);
ret = player_playback_start(&id); ret = player_playback_start(&id);
if (ret < 0) if (ret < 0)
{ {

View File

@ -474,6 +474,10 @@ player_queue_make_pl(int plid, uint32_t *id)
ps = player_queue_make(&qp, NULL); ps = player_queue_make(&qp, NULL);
/* Shortcut for shuffled playlist */
if (*id == 0)
return ps;
p = ps; p = ps;
i = 0; i = 0;
do do