Add buffering to MP3 streaming
The buffer class seems to work very well to avoid hiccups while streaming from the web, so add it by default to the example to make it easier for users to cut-n-paste and make it work.
This commit is contained in:
1 parent
8b080899af
commit
9c3f579c96
3 files changed
+26
-2
No files matched your search
@@ -23,10 +23,14 @@
|
||||
AudioFileSourceHTTPStream::AudioFileSourceHTTPStream()
|
||||
{
|
||||
pos = 0;
|
||||
reconnect = false;
|
||||
saveURL = NULL;
|
||||
}
|
||||
|
||||
AudioFileSourceHTTPStream::AudioFileSourceHTTPStream(const char *url)
|
||||
{
|
||||
saveURL = NULL;
|
||||
reconnect = false;
|
||||
open(url);
|
||||
}
|
||||
|
||||
@@ -41,6 +45,8 @@ bool AudioFileSourceHTTPStream::open(const char *url)
|
||||
return false;
|
||||
}
|
||||
size = http.getSize();
|
||||
free(saveURL);
|
||||
saveURL = strdup(url);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -61,7 +67,19 @@ uint32_t AudioFileSourceHTTPStream::readNonBlock(void *data, uint32_t len)
|
||||
|
||||
uint32_t AudioFileSourceHTTPStream::readInternal(void *data, uint32_t len, bool nonBlock)
|
||||
{
|
||||
if (!http.connected()) return 0;
|
||||
if (!http.connected()) {
|
||||
http.end();
|
||||
Serial.println("Stream disconnected\n");
|
||||
if (reconnect) {
|
||||
if (!open(saveURL)) {
|
||||
return 0;
|
||||
} else {
|
||||
Serial.println("Reconnected to stream");
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if ((size>0) && (pos >= size)) return 0;
|
||||
|
||||
WiFiClient *stream = http.getStreamPtr();
|
||||
|
||||
Reference in new issue
Block a user