Skip to content

Commit 70bb64b

Browse files
Refactored bitrate
1 parent 516a702 commit 70bb64b

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

src/ESP32_VS1053_Stream.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,6 @@ bool ESP32_VS1053_Stream::connecttohost(const char *url, const char *username,
233233
_http->addHeader("Icy-MetaData", VS1053_ICY_METADATA ? "1" : "0");
234234
_http->setAuthorization(username, pwd);
235235

236-
const char *CONTENT_TYPE = "Content-Type";
237-
const char *ICY_NAME = "icy-name";
238-
const char *ICY_METAINT = "icy-metaint";
239-
const char *ENCODING = "Transfer-Encoding";
240-
const char *BITRATE = "icy-br";
241-
const char *LOCATION = "Location";
242-
243236
const char *header[] = {CONTENT_TYPE, ICY_NAME, ICY_METAINT,
244237
ENCODING, BITRATE, LOCATION};
245238
_http->collectHeaders(header, sizeof(header) / sizeof(char *));
@@ -331,7 +324,6 @@ bool ESP32_VS1053_Stream::connecttohost(const char *url, const char *username,
331324
_offset = (_remainingBytes == -1) ? 0 : offset;
332325
_metaDataStart = _http->header(ICY_METAINT).toInt();
333326
_musicDataPosition = _metaDataStart ? 0 : -100;
334-
_bitrate = _http->header(BITRATE).toInt();
335327
if (strcmp(_url, url) || !_offset)
336328
{
337329
_vs1053->stopSong();
@@ -678,7 +670,7 @@ void ESP32_VS1053_Stream::loop()
678670

679671
if (_startMute)
680672
{
681-
const auto WAIT_TIME_MS = ((!_bitrate && _remainingBytes == -1) ||
673+
const auto WAIT_TIME_MS = ((!bitrate() && _remainingBytes == -1) ||
682674
_currentCodec == AAC || _currentCodec == AACP || _currentCodec == OGG)
683675
? 380
684676
: 80;
@@ -733,7 +725,6 @@ void ESP32_VS1053_Stream::stopSong()
733725
_remainingBytes = 0;
734726
_bytesLeftInChunk = 0;
735727
_currentCodec = STOPPED;
736-
_bitrate = 0;
737728
_offset = 0;
738729
}
739730

@@ -778,7 +769,7 @@ size_t ESP32_VS1053_Stream::position()
778769

779770
uint32_t ESP32_VS1053_Stream::bitrate()
780771
{
781-
return _bitrate;
772+
return _http ? _http->header(BITRATE).toInt() : 0;
782773
}
783774

784775
const char *ESP32_VS1053_Stream::bufferStatus()

src/ESP32_VS1053_Stream.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ class ESP32_VS1053_Stream
9595
int32_t _metaDataStart = 0;
9696
int32_t _musicDataPosition = 0;
9797
uint8_t _volume = VS1053_INITIALVOLUME;
98-
int _bitrate = 0;
9998
bool _chunkedResponse = false;
10099
bool _dataSeen = false;
101100
bool _ringbuffer_filled = false;
@@ -110,6 +109,13 @@ class ESP32_VS1053_Stream
110109
AAC,
111110
AACP
112111
} _currentCodec = STOPPED;
112+
113+
const char *CONTENT_TYPE = "Content-Type";
114+
const char *ICY_NAME = "icy-name";
115+
const char *ICY_METAINT = "icy-metaint";
116+
const char *ENCODING = "Transfer-Encoding";
117+
const char *BITRATE = "icy-br";
118+
const char *LOCATION = "Location";
113119
};
114120

115121
#endif

0 commit comments

Comments
 (0)