Add callbacks for metadata and status reports
All objects can have a metadata and/or status report callback once created. They will call the source program with the parsed ID3 tag, ICY StreamTitle, or text and numeric error ID of any interesting event. It is up to the end application to figure out what to do with this. Normally, you'd just print it to the LCD or Serial port. But it is possible to detect, say, a buffer overflow and then switch to a lower bitrate stream for example.
This commit is contained in:
1 parent
1ab9348a4c
commit
9c120a777a
22 files changed
+339
-85
No files matched your search
@@ -1,6 +1,6 @@
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include "AudioFileSourceHTTPStream.h"
|
||||
#include "AudioFileSourceICYStream.h"
|
||||
#include "AudioFileSourceSPIRAMBuffer.h"
|
||||
#include "AudioGeneratorMP3.h"
|
||||
#include "AudioOutputI2SNoDAC.h"
|
||||
@@ -15,10 +15,27 @@ const char *PASSWORD = ".....";
|
||||
const char *URL="http://streaming.shoutcast.com/80sPlanet?lang=en-US";
|
||||
|
||||
AudioGeneratorMP3 *mp3;
|
||||
AudioFileSourceHTTPStream *file;
|
||||
AudioFileSourceICYStream *file;
|
||||
AudioFileSourceSPIRAMBuffer *buff;
|
||||
AudioOutputI2SNoDAC *out;
|
||||
|
||||
// Called when a metadata event occurs (i.e. an ID3 tag, an ICY block, etc.
|
||||
void MDCallback(void *cbData, const char *type, bool isUnicode, Stream *stream)
|
||||
{
|
||||
const char *ptr = reinterpret_cast<const char *>(cbData);
|
||||
(void) isUnicode; // Punt this ball for now
|
||||
Serial.printf("METADATA(%s) '%s' = '%s'\n", ptr, type, stream->readString().c_str());
|
||||
Serial.flush();
|
||||
}
|
||||
|
||||
// Called when there's a warning or error (like a buffer underflow or decode hiccup)
|
||||
void StatusCallback(void *cbData, int code, const char *string)
|
||||
{
|
||||
const char *ptr = reinterpret_cast<const char *>(cbData);
|
||||
Serial.printf("STATUS(%s) '%d' = '%s'\n", ptr, code, string);
|
||||
Serial.flush();
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@@ -41,18 +58,29 @@ void setup()
|
||||
Serial.println("...Connecting to WiFi");
|
||||
delay(1000);
|
||||
}
|
||||
Serial.println("Connected");
|
||||
|
||||
file = new AudioFileSourceHTTPStream(URL);
|
||||
file = new AudioFileSourceICYStream(URL);
|
||||
file->RegisterMetadataCB(MDCallback, (void*)"ICY");
|
||||
// Initialize 23LC1024 SPI RAM buffer with chip select ion GPIO4 and ram size of 128KByte
|
||||
buff = new AudioFileSourceSPIRAMBuffer(file, 4, 131072);
|
||||
buff->RegisterStatusCB(StatusCallback, (void*)"buffer");
|
||||
out = new AudioOutputI2SNoDAC();
|
||||
mp3 = new AudioGeneratorMP3();
|
||||
mp3->RegisterStatusCB(StatusCallback, (void*)"mp3");
|
||||
mp3->begin(buff, out);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
static int lastms = 0;
|
||||
|
||||
if (mp3->isRunning()) {
|
||||
if (millis()-lastms > 1000) {
|
||||
lastms = millis();
|
||||
Serial.printf("Running for %d ms...\n", lastms);
|
||||
Serial.flush();
|
||||
}
|
||||
if (!mp3->loop()) mp3->stop();
|
||||
} else {
|
||||
Serial.printf("MP3 done\n");
|
||||
|
||||
Reference in new issue
Block a user