The buffer class seems to work very well to avoid hiccups while streaming from the web, so add it by default to the example to make it easier for users to cut-n-paste and make it work.
62 lines
1.3 KiB
Arduino
62 lines
1.3 KiB
Arduino
#include <Arduino.h>
|
|
#include <ESP8266WiFi.h>
|
|
#include "AudioFileSourceHTTPStream.h"
|
|
#include "AudioFileSourceBuffer.h"
|
|
#include "AudioGeneratorMP3.h"
|
|
#include "AudioOutputI2SNoDAC.h"
|
|
|
|
// To run, set your ESP8266 build to 160MHz, update the SSID info, and upload.
|
|
|
|
// Enter your WiFi setup here:
|
|
const char *SSID = ".....";
|
|
const char *PASSWORD = ".....";
|
|
|
|
// Randomly picked URL
|
|
const char *URL="http://streaming.shoutcast.com/80sPlanet?lang=en-US";
|
|
|
|
AudioGeneratorMP3 *mp3;
|
|
AudioFileSourceHTTPStream *file;
|
|
AudioFileSourceBuffer *buff;
|
|
AudioOutputI2SNoDAC *out;
|
|
|
|
void setup()
|
|
{
|
|
Serial.begin(115200);
|
|
delay(1000);
|
|
Serial.println("Connecting to WiFi");
|
|
|
|
WiFi.disconnect();
|
|
WiFi.softAPdisconnect(true);
|
|
WiFi.mode(WIFI_STA);
|
|
|
|
WiFi.hostname("melody");
|
|
|
|
byte zero[] = {0,0,0,0};
|
|
WiFi.config(zero, zero, zero, zero);
|
|
|
|
WiFi.begin(SSID, PASSWORD);
|
|
|
|
// Try forever
|
|
while (WiFi.status() != WL_CONNECTED) {
|
|
Serial.println("...Connecting to WiFi");
|
|
delay(1000);
|
|
}
|
|
|
|
file = new AudioFileSourceHTTPStream(URL);
|
|
buff = new AudioFileSourceBuffer(file, 2048);
|
|
out = new AudioOutputI2SNoDAC();
|
|
mp3 = new AudioGeneratorMP3();
|
|
mp3->begin(buff, out);
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
if (mp3->isRunning()) {
|
|
if (!mp3->loop()) mp3->stop();
|
|
} else {
|
|
Serial.printf("MP3 done\n");
|
|
delay(1000);
|
|
}
|
|
}
|
|
|