Add inline ID3 decoder w/callback interface
ID3 tags can now automatically give your app a callback with different tag types without any additional work on your application. See the PlayMP3 example for a very simple example of AudioFileSourceID3's use.
This commit is contained in:
1 parent
fece88a9be
commit
75268b5e3b
6 files changed
+309
-2
No files matched your search
@@ -1,6 +1,7 @@
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include "AudioFileSourceSPIFFS.h"
|
||||
#include "AudioFileSourceID3.h"
|
||||
#include "AudioGeneratorMP3.h"
|
||||
#include "AudioOutputI2SNoDAC.h"
|
||||
|
||||
@@ -13,6 +14,30 @@
|
||||
AudioGeneratorMP3 *mp3;
|
||||
AudioFileSourceSPIFFS *file;
|
||||
AudioOutputI2SNoDAC *out;
|
||||
AudioFileSourceID3 *id3;
|
||||
|
||||
void ID3Callback(const char *type, bool unicode, int len, AudioFileSource *src)
|
||||
{
|
||||
Serial.printf("ID3 callback for: %s = [%d bytes] '", type, len);
|
||||
if (unicode && len > 2) {
|
||||
char ign[2];
|
||||
src->read(&ign, 2);
|
||||
len -= 2;
|
||||
}
|
||||
while (len) {
|
||||
char a, b;
|
||||
src->read(&a, 1);
|
||||
len--;
|
||||
if (unicode && len) {
|
||||
src->read(&b, 1);
|
||||
len--;
|
||||
}
|
||||
Serial.printf("%c", a);
|
||||
}
|
||||
Serial.printf("'\n");
|
||||
Serial.flush();
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
@@ -20,10 +45,13 @@ void setup()
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
SPIFFS.begin();
|
||||
Serial.printf("Sample MP3 playback begins...\n");
|
||||
file = new AudioFileSourceSPIFFS("/pno-cs.mp3");
|
||||
id3 = new AudioFileSourceID3(file);
|
||||
id3->setCallback(ID3Callback);
|
||||
out = new AudioOutputI2SNoDAC();
|
||||
mp3 = new AudioGeneratorMP3();
|
||||
mp3->begin(file, out);
|
||||
mp3->begin(id3, out);
|
||||
}
|
||||
|
||||
void loop()
|
||||
@@ -35,4 +63,3 @@ void loop()
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in new issue
Block a user