Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playing Mp3 from SD_MMC is not working #650

Open
Talha-Babar opened this issue Sep 24, 2023 · 0 comments
Open

Playing Mp3 from SD_MMC is not working #650

Talha-Babar opened this issue Sep 24, 2023 · 0 comments

Comments

@Talha-Babar
Copy link

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 <Arduino.h>
#include "SD_MMC.h"
#include <AudioFileSourceFS.h>
#include <AudioGeneratorMP3.h>
#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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant