earlephilhower / ESP8266Audio

Arduino library to play MOD, WAV, FLAC, MIDI, RTTTL, MP3, and AAC files on I2S DACs or with a software emulated delta-sigma DAC on the ESP8266 and ESP32
GNU General Public License v3.0
2.02k stars 432 forks source link

Playing Mp3 from SD_MMC is not working #650

Open Talha-Babar opened 1 year ago

Talha-Babar commented 1 year ago

I need help in an issue; I have develop the code for esp32 to play mp3 file from the sd_mmc using I2S. I believe the esp32 is reading perfectly from the card but not able to play it. The hardware i am using is ESP32, MAX98357A I2S amplifier module and SD_CARD_MMC.

Here is the code: `#define MP3_FILENAME "/video/audio.mp3"

include

include "SD_MMC.h"

include

include

include "AudioOutputI2SNoDAC.h"

static AudioGeneratorMP3 mp3; static AudioOutputI2SNoDAC out; // Use AudioOutputI2SNoDAC for MAX98357A static AudioFileSourceFS *aFile;

void setup() { Serial.begin(115200);

// Init SD card if (!SD_MMC.begin("/sdcard", true)) // 1 bit mode { Serial.println(F("ERROR: SD card mount failed!")); while (1); }

out = new AudioOutputI2SNoDAC(); // Output to MAX98357A out->SetPinout(22, 26, 25); // DOUT on pin GPIO_22, BCLK on pin GPIO_26, LRC on pin GPIO_25 out->SetGain(2); mp3 = new AudioGeneratorMP3();

// Open the MP3 file aFile = new AudioFileSourceFS(SD_MMC, MP3_FILENAME); if (!aFile) { Serial.println(F("MP3 file not found!")); while (1); }

Serial.println(F("End Setup")); }

void loop() { Serial.println(F("MP3 audio start"));

// Init audio mp3->begin(aFile, out);

// Play audio while (mp3->isRunning()) { Serial.println(F("MP3 is Running")); Serial.println(mp3->isRunning()); if (!mp3->loop()) { Serial.println(F("MP3 Stop")); mp3->stop(); } }

aFile->close(); Serial.println(F("MP3 audio end")); delay(5000); }`

From the print statement i think in starts playing and stop immediately. Here is the log: 20230923_201159

Any help :)