Arduino library to play MOD, WAV, FLAC, MIDI, RTTTL, MP3, and AAC files on I2S DACs or with a software emulated delta-sigma DAC on the ESP8266 and ESP32
GNU General Public License v3.0
2.01k
stars
432
forks
source link
Play remote mp3 file not streaming only play the mp3 file #514
Hi dears!
I have a mp3 file hosted in my web server and this my url:
http://192.168.0.95/fmyapp/song.mp3
I would like to play it, this is not one radio streaming only is a simple mp3 file hosted in one apache server.
To do that I'm using the example StreamMP3FromHTTP however only works for streaming and the example works.
And it says that we only should update the class AudioFileSourceICYStream with AudioFileSourceHTTPStream
and get rid of the metadata callback and it should just work, However for me it doesn't worked, I'm getting always
Mp3 done, I would like to know if this is possible or it can't, please dear if you have some example to do that I will appreciate.
This is my current code:
#include <Arduino.h>
#ifdef ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
#include "AudioFileSourceICYStream.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 = "wifiapp";
const char *PASSWORD = "xxx22x22";
// Uncomment one link (I have added 6 radio streaming link, you can check each)
//flawlessly working radio streaming link
const char *URL="http://192.168.0.95/firebase/song.mp3"; //'N-JOY vom NDR - www.n-joy.de'
AudioGeneratorMP3 *mp3;
AudioFileSourceHTTPStream *file;
AudioFileSourceBuffer *buff;
AudioOutputI2SNoDAC *out;
// Called when there's a warning or error (like a buffer underflow or decode hiccup)
void StatusCallback(void *cbData, int code, const char *string){
const char *ptr = reinterpret_cast<const char *>(cbData);
// Note that the string may be in PROGMEM, so copy it to RAM for printf
char s1[64];
strncpy_P(s1, string, sizeof(s1));
s1[sizeof(s1)-1]=0;
Serial.printf("STATUS(%s) '%d' = '%s'\n", ptr, code, s1);
Serial.flush();
}
void setup(){
Serial.begin(115200);
delay(1000);
Serial.println("Connecting to WiFi");
WiFi.disconnect();
WiFi.softAPdisconnect(true);
WiFi.mode(WIFI_STA);
WiFi.begin(SSID, PASSWORD);
// Try forever
while (WiFi.status() != WL_CONNECTED) {
Serial.println("...Connecting to WiFi");
delay(1000);
}
Serial.println("Connected");
audioLogger = &Serial;
file = new AudioFileSourceICYStream(URL);
buff = new AudioFileSourceBuffer(file, 8192);
buff->RegisterStatusCB(StatusCallback, (void*)"buffer");
out = new AudioOutputI2SNoDAC();
mp3 = new AudioGeneratorMP3();
mp3->RegisterStatusCB(StatusCallback, (void*)"mp3");
mp3->begin(buff, out);
}
void loop(){
static int lastms = 0;
if (mp3->isRunning()) {
if (millis()-lastms > 1000) {
lastms = millis();
Serial.printf("Running for %d ms...\n", lastms);
Serial.flush();
}
if (!mp3->loop()) mp3->stop();
} else {
Serial.printf("MP3 done\n");
delay(1000);
}
}
Hi dears! I have a mp3 file hosted in my web server and this my url: http://192.168.0.95/fmyapp/song.mp3 I would like to play it, this is not one radio streaming only is a simple mp3 file hosted in one apache server. To do that I'm using the example
StreamMP3FromHTTP
however only works for streaming and the example works.Searching in this repository I found it: https://github.com/earlephilhower/ESP8266Audio/issues/113
And it says that we only should update the class
AudioFileSourceICYStream
withAudioFileSourceHTTPStream
and get rid of the metadata callback and it should just work, However for me it doesn't worked, I'm getting alwaysMp3 done
, I would like to know if this is possible or it can't, please dear if you have some example to do that I will appreciate.This is my current code:
thanks so much.