Created
November 20, 2019 13:48
-
-
Save CelliesProjects/022235e5d126a3b8ce1b024c43ba6de5 to your computer and use it in GitHub Desktop.
M5Stack Fire - Play a web stream on internal DAC.
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 | |
| Use the "Tools->ESP32 Sketch Data Upload" menu to write the MP3 to SPIFFS | |
| Then upload the sketch normally. | |
| https://github.com/me-no-dev/arduino-esp32fs-plugin | |
| */ | |
| #include <M5Stack.h> | |
| #include <WiFi.h> | |
| #include "SPIFFS.h" | |
| #include "AudioFileSourceHTTPStream.h" | |
| #include "AudioFileSourceBuffer.h" | |
| #include "AudioGeneratorMP3.h" | |
| #include "AudioOutputI2S.h" | |
| AudioGeneratorMP3 *mp3; | |
| AudioFileSourceHTTPStream *file; | |
| AudioFileSourceBuffer *buff; | |
| AudioOutputI2S *out; | |
| const char * url = "http://icecast.omroep.nl/radio2-bb-mp3"; | |
| void setup() | |
| { | |
| M5.begin(); | |
| M5.Lcd.setTextFont(2); | |
| WiFi.begin(); | |
| M5.Lcd.printf("Connecting WiFi...\n"); | |
| while ( !WiFi.isConnected() ) delay(100); | |
| //SPIFFS.begin(); | |
| delay(500); | |
| M5.Lcd.printf( "Streaming %s\n", url ); | |
| file = new AudioFileSourceHTTPStream(url); | |
| // Create a buffer using that stream | |
| buff = new AudioFileSourceBuffer( file, 4096 ); | |
| out = new AudioOutputI2S(0, 1); // Output to builtInDAC | |
| mp3 = new AudioGeneratorMP3(); | |
| // Pass in the *buffer*, not the *http stream* to enable buffering | |
| mp3->begin(buff, out); | |
| } | |
| void loop() | |
| { | |
| if (mp3->isRunning()) { | |
| if (!mp3->loop()) mp3->stop(); | |
| } else { | |
| Serial.printf("MP3 done\n"); | |
| delay(10); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment