From ab9b330127eeeddd3d8e39861d6f1b0111ae6398 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Fri, 6 Apr 2018 15:13:05 +0200 Subject: [PATCH] http redirection --- src/mp3.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/mp3.cpp b/src/mp3.cpp index 55603f7..2d3d835 100644 --- a/src/mp3.cpp +++ b/src/mp3.cpp @@ -19,6 +19,8 @@ #include "esp_system.h" #include +#include "HTTPClient.h" + #include "alarmsound.h" char titleStr[64]; @@ -118,7 +120,22 @@ void MP3::mp3_decoder_task(void *pvParameters) { // strcpy(titleStr, "loading..."); if (fromProgmem) file = new AudioFileSourcePROGMEM(alarmsound, alarmsound_len); else if (rtttl_len > 0) file = new AudioFileSourcePROGMEM( rtttl, rtttl_len ); - else file = new AudioFileSourceICYStream(URL); + else { + HTTPClient http; + http.begin(URL); + const char* headerNames[] = { "Location", "Last-Modified" }; + http.collectHeaders(headerNames, sizeof(headerNames)/sizeof(headerNames[0])); + int httpCode = http.GET(); + if (httpCode == HTTP_CODE_FOUND || httpCode == HTTP_CODE_SEE_OTHER) { // check for redirect + Serial.println("redirect!!!!!!!!!!!!!!!"); + if (http.hasHeader("Location")) { + Serial.println(http.header("Location")); + http.header("Location").toCharArray(URL, 80); + } + } + http.end(); + file = new AudioFileSourceICYStream(URL); + } file->RegisterMetadataCB(MDCallback, (void*)"ICY"); buff = new AudioFileSourceBuffer(file, preallocateBuffer, preallocateBufferSize); audiobuffer = buff;