From 10f2eb2409b7fd4ac8871aae1079d02c8557e740 Mon Sep 17 00:00:00 2001 From: chme Date: Sun, 22 Feb 2015 07:20:10 +0100 Subject: [PATCH] Improve behaviour for playing from history --- src/httpd_dacp.c | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/src/httpd_dacp.c b/src/httpd_dacp.c index ef1a95bc..6eba110f 100644 --- a/src/httpd_dacp.c +++ b/src/httpd_dacp.c @@ -727,6 +727,8 @@ dacp_reply_cue_play(struct evhttp_request *req, struct evbuffer *evbuf, char **u uint32_t id; uint32_t pos; int clear; + struct player_history *history; + int hist; int ret; /* /cue?command=play&query=...&sort=...&index=N */ @@ -783,12 +785,43 @@ dacp_reply_cue_play(struct evhttp_request *req, struct evbuffer *evbuf, char **u DPRINTF(E_LOG, L_DACP, "Invalid index (%s) in cue request\n", param); } - /* If selection was from Up Next queue (command will be playnow), then index is relative */ - //TODO playnow for mode = 1 (index is relativ to the history queue + /* If selection was from Up Next queue or history queue (command will be playnow), then index is relative */ + hist = 0; if ((param = evhttp_find_header(query, "command")) && (strcmp(param, "playnow") == 0)) - pos += status.pos_pl; + { + /* If mode parameter is -1, the index is relative to the history queue, otherwise to the Up Next queue */ + param = evhttp_find_header(query, "mode"); + if (param && (strcmp(param, "-1") == 0)) + { + /* Play from history queue */ + hist = 1; + history = player_history_get(); + if (history->count > pos) + { + pos = (history->start_index + history->count - pos - 1) % MAX_HISTORY_COUNT; + id = history->id[pos]; + } + else + { + DPRINTF(E_LOG, L_DACP, "Could not start playback from history\n"); + + dmap_send_error(req, "cacr", "Playback failed to start"); + return; + } + } + else + { + /* Play from Up Next queue */ + pos += status.pos_pl; + } + } + + /* If playing from history queue, the pos holds the id of the item to play */ + if (hist) + ret = player_playback_startid(id, &id); + else + ret = player_playback_startpos(pos, &id); - ret = player_playback_startpos(pos, &id); if (ret < 0) { DPRINTF(E_LOG, L_DACP, "Could not start playback\n");