Last active
November 22, 2024 06:09
-
-
Save mongonta0716/18c28bff2dc533d8b51903c939a66a61 to your computer and use it in GitHub Desktop.
Example of MP3 Play for M5Stack Core2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma mark - Depend ESP8266Audio and ESP8266_Spiram libraries | |
/* | |
cd ~/Arduino/libraries | |
git clone https://github.com/earlephilhower/ESP8266Audio | |
git clone https://github.com/Gianbacchio/ESP8266_Spiram | |
*/ | |
#include <M5Core2.h> | |
#include <driver/i2s.h> | |
#include <WiFi.h> | |
#include "AudioFileSourceSD.h" | |
#include "AudioFileSourceID3.h" | |
#include "AudioGeneratorMP3.h" | |
#include "AudioOutputI2S.h" | |
AudioGeneratorMP3 *mp3; | |
AudioFileSourceSD *file; | |
AudioOutputI2S *out; | |
AudioFileSourceID3 *id3; | |
#define OUTPUT_GAIN 10 | |
void setup() | |
{ | |
M5.begin(); | |
M5.Axp.SetSpkEnable(true); | |
WiFi.mode(WIFI_OFF); | |
delay(500); | |
M5.Lcd.setTextFont(2); | |
M5.Lcd.printf("Sample MP3 playback begins...\n"); | |
Serial.printf("Sample MP3 playback begins...\n"); | |
// pno_cs from https://ccrma.stanford.edu/~jos/pasp/Sound_Examples.html | |
file = new AudioFileSourceSD("/mp3/chikichiki.mp3"); | |
id3 = new AudioFileSourceID3(file); | |
out = new AudioOutputI2S(0, 0); // Output to builtInDAC | |
out->SetPinout(12, 0, 2); | |
out->SetOutputModeMono(true); | |
out->SetGain((float)OUTPUT_GAIN/100.0); | |
mp3 = new AudioGeneratorMP3(); | |
mp3->begin(id3, out); | |
} | |
void loop() | |
{ | |
if (mp3->isRunning()) { | |
if (!mp3->loop()) mp3->stop(); | |
} else { | |
Serial.printf("MP3 done\n"); | |
delay(1000); | |
} | |
} |
This is for SD cards, not SPIFFS.
use AudioFileSourceSPIFFS.
You need to rewrite the SPIFFS part. Please refer to here.
Perhaps you also need to add the following line.
SPIFFS.begin();
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sure this works? Cant get any results... File was uploaded correctly to SPIFFS.