I have extended my arduino-audio-tools project to provide access to MP3 Meta Data.
ID3 is the metadata container which is most often used in conjunction with the MP3 audio file format. It allows information such as the title, artist, album, track number, and other information about the file to be stored in the file itself.

Both versions of ID3 (ID3v1 and ID3v2) are supported. I currently however only provide the information that is available in both which is:

  • Artist
  • Album
  • Title
  • Genre

The MetaDataID3 class is used as stream output destination and you register your callback method with setCallback():

#include "AudioTools.h"
#include "sample-12s.h"

using namespace audio_tools;  

MemoryStream mp3(sample_12s_mp3, sample_12s_mp3_len);
MetaDataID3 out;
StreamCopy copier(out, mp3); // copy in to out
bool title_printed = false;

// callback for meta data
void printMetaData(MetaDataType type, const char* str, int len){
  Serial.print("==> ");
  Serial.print(MetaDataTypeStr[type]);
  Serial.print(": ");
  Serial.println(str);
  title_printed = true;
}

void setup(){
  Serial.begin(115200);
  AudioLogger::instance().begin(Serial, AudioLogger::Info);  

  out.setCallback(printMetaData);
  out.begin();
  mp3.begin();
}

void loop(){
  if (mp3) {
    copier.copy();
  } else {
    stop();
  }
}

The complete example is available on Github


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published.