summaryrefslogtreecommitdiff
path: root/src/player.c
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@lavabit.com>2008-10-17 20:00:56 +0200
committerLars-Dominik Braun <PromyLOPh@lavabit.com>2008-10-17 20:00:56 +0200
commit56b1686b8c27a0b01d0ae3f50615974d03574947 (patch)
treea0b2c7cf833fcc5ccd0fe2e89db7a79f98bb3233 /src/player.c
parent3fa2e6d50393d0acd683a23989a5b49e615adc66 (diff)
downloadpianobar-56b1686b8c27a0b01d0ae3f50615974d03574947.tar.gz
pianobar-56b1686b8c27a0b01d0ae3f50615974d03574947.tar.bz2
pianobar-56b1686b8c27a0b01d0ae3f50615974d03574947.zip
Resume aborted song transfer
This fixes those my-favorite-song-suddenly-aborted-"bugs", as well as the pause mode, which was more like a stop mode, because pandora *always* aborted the transfer after a few minutes.
Diffstat (limited to 'src/player.c')
-rw-r--r--src/player.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/player.c b/src/player.c
index b009b4f..57fc443 100644
--- a/src/player.c
+++ b/src/player.c
@@ -76,6 +76,7 @@ size_t BarPlayerCurlCb (void *ptr, size_t size, size_t nmemb, void *stream) {
memcpy (player->buffer+player->bufferFilled, data, size*nmemb);
player->bufferFilled += size*nmemb;
player->bufferRead = 0;
+ player->bytesReceived += size*nmemb;
if (player->mode == PLAYER_RECV_DATA) {
short int *aacDecoded;
@@ -231,6 +232,9 @@ size_t BarPlayerCurlCb (void *ptr, size_t size, size_t nmemb, void *stream) {
void *BarPlayerThread (void *data) {
struct aacPlayer *player = data;
NeAACDecConfigurationPtr conf;
+ struct curl_slist *extraHeader = NULL;
+ char rangeHeader[255];
+ CURLcode curlRet = 0;
/* init handles */
player->audioFd = curl_easy_init ();
@@ -254,7 +258,21 @@ void *BarPlayerThread (void *data) {
player->mode = PLAYER_INITIALIZED;
- curl_easy_perform (player->audioFd);
+ /* This loop should work around song abortions by requesting the
+ * missing part of the song */
+ do {
+ /* if curl failed, setup new headers _everytime_ (the range changed) */
+ if (curlRet == CURLE_PARTIAL_FILE) {
+ snprintf (rangeHeader, sizeof (rangeHeader),
+ "Range: bytes=%i-", player->bytesReceived);
+ extraHeader = curl_slist_append (extraHeader, rangeHeader);
+ curl_easy_setopt (player->audioFd, CURLOPT_HTTPHEADER,
+ extraHeader);
+ }
+ curlRet = curl_easy_perform (player->audioFd);
+ curl_slist_free_all (extraHeader);
+ extraHeader = NULL;
+ } while (curlRet == CURLE_PARTIAL_FILE);
NeAACDecClose(player->aacHandle);
ao_close(player->audioOutDevice);