33 audio.cpp
44
55 Created on: Oct 28.2018 */ char audioI2SVers[] =" \
6- Version 3.4.0h " ;
7- /* Updated on: Jul 26 .2025
6+ Version 3.4.0i " ;
7+ /* Updated on: Jul 28 .2025
88
99 Author: Wolle (schreibfaul1)
1010 Audio library for ESP32, ESP32-S3 or ESP32-P4
@@ -791,15 +791,15 @@ bool Audio::httpPrint(const char* host) {
791791 rqh.append (" \r\n " );
792792 rqh.append (" Icy-MetaData:1\r\n " );
793793 rqh.append (" Icy-MetaData:2\r\n " );
794- rqh.append (" Accept: */*\r\n " );
794+ rqh.append (" Accept:*/*\r\n " );
795795 rqh.append (" User-Agent: VLC/3.0.21 LibVLC/3.0.21 AppleWebKit/537.36 (KHTML, like Gecko)\r\n " );
796796 rqh.append (" Accept-Encoding: identity;q=1,*;q=0\r\n " );
797797 rqh.append (" Connection: keep-alive\r\n\r\n " );
798798
799799 AUDIO_INFO (" next URL: \" %s\" " , c_host.get ());
800800
801801 if (f_equal == false ){
802- _client->stop ();
802+ if (_client-> connected ()) _client->stop ();
803803 }
804804 if (!_client->connected () ) {
805805 if (m_f_ssl) { _client = static_cast <WiFiClient*>(&clientsecure); if (m_f_ssl && port == 80 ) port = 443 ;}
@@ -836,7 +836,7 @@ bool Audio::httpPrint(const char* host) {
836836 return true ;
837837}
838838// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
839- bool Audio::httpRange (uint32_t range ){
839+ bool Audio::httpRange (uint32_t seek, uint32_t length ){
840840
841841 if (!m_f_running) return false ;
842842
@@ -848,6 +848,7 @@ bool Audio::httpRange(uint32_t range){
848848 ps_ptr<char > path; // extension + '?' + parameter
849849 ps_ptr<char > rqh; // request header
850850 ps_ptr<char > cur_hwoe; // m_currenthost without extension
851+ ps_ptr<char > range; // e.g. "Range: bytes=124-"
851852
852853 c_host.clone_from (m_currentHost);
853854 c_host.trim ();
@@ -878,30 +879,33 @@ bool Audio::httpRange(uint32_t range){
878879 auto dismantledLastHost = dismantle_host (m_currentHost.get ());
879880 cur_hwoe.clone_from (dismantledLastHost.hwoe );
880881
882+ if (length == UINT32_MAX) range.assignf (" Range: bytes=%li-\r\n " ,seek);
883+ else range.assignf (" Range: bytes=%li-%li\r\n " ,seek, length);
884+
881885 rqh.assignf (" GET /%s HTTP/1.1\r\n " , path.get ());
882886 rqh.appendf (" Host: %s\r\n " , hwoe.get ());
883887 rqh.append (" Accept: */*\r\n " );
884888 rqh.append (" Accept-Encoding: identity;q=1,*;q=0\r\n " );
885889 rqh.append (" Cache-Control: no-cache\r\n " );
886890 rqh.append (" Connection: keep-alive\r\n " );
887- rqh.appendf (" Range: bytes=%i- \r\n " , range);
891+ rqh.appendf (range. c_get () );
888892 rqh.appendf (" Referer: %s\r\n " , m_currentHost.c_get ());
889893 rqh.append (" Sec-GPC: 1\r\n " );
890894 rqh.append (" User-Agent: VLC/3.0.21 LibVLC/3.0.21 AppleWebKit/537.36 (KHTML, like Gecko)\r\n\r\n " );
891895
892- if (!_client->connected ()) {
893- AUDIO_LOG_INFO (" Verbindung geschlossen, stelle neu her" );
894- _client->stop (); // Schließe alte Verbindung
895- if (!_client->connect (hwoe.get (), port)) {
896- AUDIO_LOG_ERROR (" Verbindung fehlgeschlagen" );
897- return false ;
898- }
896+ if (_client->connected ()) {_client->stop ();}
897+ if (m_f_ssl) { _client = static_cast <WiFiClient*>(&clientsecure); if (m_f_ssl && port == 80 ) port = 443 ;}
898+ else { _client = static_cast <WiFiClient*>(&client); }
899+
900+ if (!_client->connect (hwoe.get (), port)) {
901+ AUDIO_LOG_ERROR (" connection lost %s" , c_host.c_get ());
902+ stopSong ();
903+ return false ;
899904 }
900905
901- AUDIO_LOG_INFO (" av %i" , _client->available ());
902- AUDIO_LOG_INFO (" rqh \n %s" , rqh.get ());
906+ // AUDIO_LOG_INFO("rqh \n%s", rqh.get());
903907
904- _client->print (rqh.get ());
908+ _client->print (rqh.c_get ());
905909
906910 m_dataMode = HTTP_RANGE_HEADER;
907911 m_streamType = ST_WEBFILE;
@@ -1988,24 +1992,23 @@ int Audio::read_ID3_Header(uint8_t* data, size_t len) {
19881992 m_ID3Hdr.SYLT .seen = true ;
19891993 m_ID3Hdr.SYLT .pos = m_ID3Hdr.id3Size - m_ID3Hdr.remainingHeaderBytes ;
19901994 m_ID3Hdr.SYLT .size = m_ID3Hdr.framesize ;
1991- syltBuff.alloc (m_ID3Hdr.SYLT .size , " syltBuff" );
1995+ syltBuff.alloc (m_ID3Hdr.SYLT .size + 1 , " syltBuff" );
19921996 if (m_streamType == ST_WEBFILE && m_f_acceptRanges){
19931997 uint32_t pos = m_pwf.byteCounter ;
19941998 // log_w("m_audiofile.position() %i, m_ID3Hdr.SYLT.pos %i", pos, m_ID3Hdr.SYLT.pos);
19951999 bool res;
1996- res = httpRange (m_ID3Hdr.SYLT .pos );
1997- if (!res) AUDIO_LOG_ERROR (" http range request was not successful" );
1998- if (res == false ) return 0 ;
2000+ res = httpRange (m_ID3Hdr.SYLT .pos , m_ID3Hdr.SYLT .pos + m_ID3Hdr.SYLT .size );
2001+ if (res == false ){AUDIO_LOG_ERROR (" http range request was not successful" ); return 0 ;}
19992002 res = parseHttpRangeHeader ();
2000- if (! res) AUDIO_LOG_ERROR (" http range response was not successful" );
2003+ if (res == false ){ AUDIO_LOG_ERROR (" http range response was not successful" ); return 0 ;}
20012004 uint16_t bytesWritten = 0 ;
20022005 while (bytesWritten < m_ID3Hdr.SYLT .size ){
20032006 bytesWritten += _client->read ((uint8_t *)syltBuff.get () + bytesWritten, m_ID3Hdr.SYLT .size );
20042007 }
20052008 res = httpRange (pos);
2006- if (!res) AUDIO_LOG_ERROR (" http range request was not successful" );
2009+ if (!res){ AUDIO_LOG_ERROR (" http range request was not successful" ); return 0 ;}
20072010 res = parseHttpRangeHeader ();
2008- if (!res) AUDIO_LOG_ERROR (" http range response was not successful" );
2011+ if (!res){ AUDIO_LOG_ERROR (" http range response was not successful" ); return 0 ;}
20092012 // return 0;
20102013 }
20112014 if (m_dataMode == AUDIO_LOCALFILE){
@@ -4368,7 +4371,7 @@ bool Audio::parseHttpRangeHeader() { // this is the response to a Range request
43684371 vTaskDelay (5 );
43694372 continue ;
43704373 }
4371-
4374+ // AUDIO_LOG_WARN("rh %s", rhl.c_get());
43724375 if (rhl.starts_with_icase (" HTTP/" )) { // HTTP status error code
43734376 char statusCode[5 ];
43744377 statusCode[0 ] = rhl[9 ];
0 commit comments