@@ -395,6 +395,7 @@ bool ESP32_VS1053_Stream::connectToHost(const char *url, const char *username,
395395 default :
396396 log_d (" error %i %s" , HTTPresult, _http->errorToString (HTTPresult).c_str ());
397397 stopSong ();
398+ _redirectCount = 0 ;
398399 return false ;
399400 }
400401}
@@ -448,7 +449,7 @@ void ESP32_VS1053_Stream::_playFromRingBuffer()
448449 _vs1053->playChunk (data, size);
449450 vRingbufferReturnItem (_ringbuffer_handle, data);
450451 bytesToDecoder += size;
451- _remainingBytes = (_remainingBytes > size) ? _remainingBytes - size : 0 ;
452+ _remainingBytes -= size;
452453 }
453454 log_d (" %lu ms moving %i bytes ringbuffer->decoder" , millis () - startTimeMS, bytesToDecoder);
454455}
@@ -674,10 +675,12 @@ void ESP32_VS1053_Stream::loop()
674675 if (!_http)
675676 return ;
676677
677- if (!_http->connected ())
678+ if (!_http->connected () && _ringbuffer_handle )
678679 {
679- log_e (" Stream disconnect" );
680- _eofStream ();
680+ if (_remainingBytes)
681+ _playFromRingBuffer ();
682+ else
683+ _eofStream ();
681684 return ;
682685 }
683686
@@ -947,9 +950,8 @@ void ESP32_VS1053_Stream::_readBitRate()
947950 const uint8_t SCI_HDAT1 = 0x09 ;
948951
949952 uint16_t hdat1 = _vs1053->readRegister (SCI_HDAT1);
950- uint16_t hdat0 = _vs1053->readRegister (SCI_HDAT0);
951953
952- if (hdat1 == 0 && hdat0 == 0 ) // decoder not locked yet
954+ if (hdat1 == 0 ) // decoder not locked yet
953955 {
954956 if (++_decoderSyncAttempts > 4 )
955957 {
@@ -1007,6 +1009,8 @@ void ESP32_VS1053_Stream::_readBitRate()
10071009 if (!_bitrateCallback)
10081010 return ;
10091011
1012+ uint16_t hdat0 = _vs1053->readRegister (SCI_HDAT0);
1013+
10101014 uint32_t bitrate = 0 ;
10111015
10121016 if (_codec == CODEC_MP3)
0 commit comments