Skip to main content

MP3 Player

This project demonstrates how to use the reSpeaker Lite board to play MP3 files stored in the SPIFFS file system.

Library Required

Functionality

  • Plays MP3 files from the SPIFFS file system
  • Utilizes the I2S interface for audio output
  • Supports metadata extraction and callback
  • Easy-to-use AudioPlayer class for seamless audio playback

Code

#include "AudioTools.h"
#include "AudioLibs/AudioSourceSPIFFS.h"
#include "AudioCodecs/CodecMP3Helix.h"

const char *startFilePath="/";
const char* ext="mp3";
AudioSourceSPIFFS source(startFilePath, ext);
I2SStream i2s;
MP3DecoderHelix decoder;
AudioPlayer player(source, i2s, decoder);

void printMetaData(MetaDataType type, const char* str, int len){
Serial.print("==> ");
Serial.print(toStr(type));
Serial.print(": ");
Serial.println(str);
}

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

// setup output
auto cfg = i2s.defaultConfig(TX_MODE);
i2s.begin(cfg);

// setup player
//source.setFileFilter("*Bob Dylan*");
player.setMetadataCallback(printMetaData);
player.begin();
}

void loop() {
player.copy();
}

Configuration

  • Uploading Files to SPIFFS

SPIFFS is a file system intended for SPI NOR flash devices on embedded targets. It supports wear levelling, file system consistency checks, and more.

Make sure you have the necessary tools to upload files to SPIFFS. You can use the ESP32 Sketch Data Upload tool in the Arduino IDE 1.x or other tools.

For Arduino IDE 2.x

Install:

Copy the VSIX file to ~/.arduinoIDE/plugins/ on Mac and Linux
or C:\Users\<username>\.arduinoIDE\plugins\ on Windows (you may need to make this directory yourself beforehand).
Then restart the IDE.

Usage:

For windows: [Ctrl] + [Shift] + [P], then Upload LittleFS to Pico/ESP8266/ESP32.
For macOS, [⌘] + [Shift] + [P], then Upload LittleFS to Pico/ESP8266/ESP32.

Create a folder named "data" in your sketch directory and place the MP3 files you want to play inside it.

Upload the files to SPIFFS using the chosen tool.

Loading Comments...