Skip to content

Instantly share code, notes, and snippets.

@CelliesProjects
Created November 20, 2019 13:48
Show Gist options
  • Select an option

  • Save CelliesProjects/022235e5d126a3b8ce1b024c43ba6de5 to your computer and use it in GitHub Desktop.

Select an option

Save CelliesProjects/022235e5d126a3b8ce1b024c43ba6de5 to your computer and use it in GitHub Desktop.
M5Stack Fire - Play a web stream on internal DAC.
#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