Skip to content

Commit c1ccce3

Browse files
Fix the playback of Ogg files when (re)-started with an offset. (#16)
And a fix for #15
1 parent 0375739 commit c1ccce3

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ void setup() {
4444
Serial.begin(115200);
4545

4646
WiFi.begin(SSID, PSK);
47+
48+
WiFi.setSleep(false);
49+
/* important to set this right! See issue #15 */
4750

4851
Serial.println("\n\nSimple vs1053 Streaming example.");
4952

examples/simple/simple.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ void setup() {
2525

2626
WiFi.begin(SSID, PSK);
2727

28+
WiFi.setSleep(false);
29+
/* important to set this right! See issue #15 */
30+
2831
Serial.println("\n\nSimple vs1053 Streaming example.");
2932

3033
while (!WiFi.isConnected())

src/ESP32_VS1053_Stream.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,12 @@ bool ESP32_VS1053_Stream::connecttohost(const char *url, const char *username,
339339
_metaDataStart = _http->header(ICY_METAINT).toInt();
340340
_musicDataPosition = _metaDataStart ? 0 : -100;
341341
_bitrate = _http->header(BITRATE).toInt();
342-
snprintf(_url, sizeof(_url), "%s", url);
342+
_url[0] = _savedStartChar;
343+
if (strcmp(_url, url)) /* 0 means strings are equal*/
344+
{
345+
_vs1053->stopSong();
346+
snprintf(_url, sizeof(_url), "%s", url);
347+
}
343348
_streamStalledTime = 0;
344349
log_d("redirected %i times", _redirectCount);
345350
_redirectCount = 0;
@@ -410,7 +415,7 @@ void ESP32_VS1053_Stream::_playFromRingBuffer()
410415
return;
411416
}
412417
const auto BAILOUT_MS = 2000;
413-
if (millis() - ringbufferEmpty > BAILOUT_MS)
418+
if (millis() - ringbufferEmpty > BAILOUT_MS)
414419
{
415420
log_e("Buffer empty for %i ms, bailing out...", BAILOUT_MS);
416421
_remainingBytes = 0;
@@ -572,7 +577,7 @@ void ESP32_VS1053_Stream::_handleChunkedStream(WiFiClient *const stream)
572577
}
573578
else
574579
{
575-
const auto MAX_TIME_MS = 15;
580+
const auto MAX_TIME_MS = 20;
576581
const auto start = millis();
577582
// size_t bytesToDecoder = 0;
578583
while (stream && stream->available() && _bytesLeftInChunk && _vs1053->data_request() && _musicDataPosition < _metaDataStart && millis() - start < MAX_TIME_MS)
@@ -693,7 +698,8 @@ void ESP32_VS1053_Stream::loop()
693698

694699
if (_startMute)
695700
{
696-
const auto WAIT_TIME_MS = ((!_bitrate && _remainingBytes == -1) || _currentCodec == AAC || _currentCodec == AACP)
701+
const auto WAIT_TIME_MS = ((!_bitrate && _remainingBytes == -1) ||
702+
_currentCodec == AAC || _currentCodec == AACP || _currentCodec == OGG)
697703
? 380
698704
: 80;
699705
if (millis() - _startMute > WAIT_TIME_MS)
@@ -738,13 +744,13 @@ void ESP32_VS1053_Stream::stopSong()
738744
_http->end();
739745
delete _http;
740746
_http = nullptr;
741-
_vs1053->stopSong();
742747
_deallocateRingbuffer();
743748
_ringbuffer_filled = false;
744749
_dataSeen = false;
745750
_remainingBytes = 0;
746751
_bytesLeftInChunk = 0;
747752
_currentCodec = STOPPED;
753+
_savedStartChar = _url[0];
748754
_url[0] = 0;
749755
_bitrate = 0;
750756
_offset = 0;
@@ -796,6 +802,6 @@ const char *ESP32_VS1053_Stream::bufferStatus()
796802
if (!_ringbuffer_handle)
797803
return "0/0";
798804
static char ringbuffer_status[24];
799-
snprintf(ringbuffer_status, sizeof(ringbuffer_status), "%i/%i", VS1053_PSRAM_BUFFER_SIZE - xRingbufferGetCurFreeSize(_ringbuffer_handle), VS1053_PSRAM_BUFFER_SIZE);
805+
snprintf(ringbuffer_status, sizeof(ringbuffer_status), "%u/%lu", VS1053_PSRAM_BUFFER_SIZE - xRingbufferGetCurFreeSize(_ringbuffer_handle), VS1053_PSRAM_BUFFER_SIZE);
800806
return ringbuffer_status;
801807
}

src/ESP32_VS1053_Stream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class ESP32_VS1053_Stream
6868
uint8_t _vs1053Buffer[VS1053_PLAYBUFFER_SIZE];
6969
uint8_t _localbuffer[VS1053_PSRAM_MAX_MOVE];
7070
char _url[VS1053_MAX_URL_LENGTH];
71+
char _savedStartChar = 0;
7172

7273
RingbufHandle_t _ringbuffer_handle;
7374
StaticRingbuffer_t *_buffer_struct;

0 commit comments

Comments
 (0)