How to handle redirected streams?

Most of my favorite streams use URL’s with temporarily redirected streams. This can be seen in Firefox, but ESPMUSE cannot handle this. For example if i enter in a browser: “”, this will be changed to: “” and plays the music. But after some time this will not work any more - neither in the browser nor in ESPMUSE, because this redirection is temporarily (HTTP-Code 302)! Therefore, the question is: How to implement this redirection with ESPMUSE?

Hi Mp3fan and welcome,

Your question is how to handle redirected stream URLs on ESP32, it seems that this library handle it :

Hi Raspiaudio,
thank you for your attention!
I think this is not what i wanted. I want to follow an redirection with HTTP-Code 302, which is initiated by the server. With the function you metioned you can get the previous station an user selected.

I found an example “StreamHttpClient” included in the ESP32-Library
(Examples/ESP32 Dev Module/HTTPClient/StreamHttpClient)
in the Arduino-IDE. And i found

If you insert one line
after the already exsting line “HTTPClient http;” in the example “StreamHttpClient.ino”, the 302-redirect is done. But the data are only printed to USB-Serial. There is no mp3-decoding and you can hear nothing. Unfortunately the ESPMUSE-libraries do not use
#include <HTTPClient.h>.
Therefore, this is not the solution, but it shows the goal.

Currently i try some additions to the internet-radio-software to handle redirected streams:

/// in Include-Section:

#include ...
#include <HTTPClient.h>

/// End Include-Section<<<

// in playRadio: change one Line, other lines unhanged as before
static void playRadio(void* ){
	audio.connecttohost(getPlayURL(linkS));  // Change:insert "getPlayURL"

//Completely new:
//  Redirect check: getPlayURL
String getPlayURL(String sURL) {
  HTTPClient http; 
  http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS); // Redirect Option
  String Location = sURL;
  int httpCode = http.GET();
  if (httpCode == HTTP_CODE_OK) {
    Location = http.getLocation();
  if (0 == Location.length()) {
    Location = sURL;
  Serial.println("sURL ----::");
  return Location;