|
|
@ -57,6 +57,7 @@ void MP3::start() { |
|
|
|
} |
|
|
|
|
|
|
|
void MP3::mp3_decoder_task(void *pvParameters) { |
|
|
|
strcpy(titleStr, "..."); |
|
|
|
file = new AudioFileSourceICYStream(URL); |
|
|
|
file->RegisterMetadataCB(MDCallback, (void*)"ICY"); |
|
|
|
buff = new AudioFileSourceBuffer(file, preallocateBuffer, preallocateBufferSize); |
|
|
@ -65,31 +66,32 @@ void MP3::mp3_decoder_task(void *pvParameters) { |
|
|
|
out = new AudioOutputI2S(I2S_NUM_0, false, 0); |
|
|
|
out->SetPinout(12, 13, 25); |
|
|
|
} |
|
|
|
mp3 = new AudioGeneratorMP3(); |
|
|
|
mp3->RegisterStatusCB(StatusCallback, (void*)"mp3"); |
|
|
|
mp3->begin(buff, out); |
|
|
|
decoder = new AudioGeneratorMP3(); |
|
|
|
decoder->RegisterStatusCB(StatusCallback, (void*)"mp3"); |
|
|
|
decoder->begin(buff, out); |
|
|
|
out->SetGain(1.0); |
|
|
|
playing = true; |
|
|
|
|
|
|
|
while(mp3->isRunning()) { |
|
|
|
while(decoder->isRunning()) { |
|
|
|
if (millis()-lastms > 1000) { |
|
|
|
lastms = millis(); |
|
|
|
Serial.printf("Running for %d ms...\n", lastms); |
|
|
|
Serial.flush(); |
|
|
|
} |
|
|
|
if (!mp3->loop()) break; |
|
|
|
if (!decoder->loop()) break; |
|
|
|
if (!playing) break; |
|
|
|
vTaskDelay(5 / portTICK_PERIOD_MS); |
|
|
|
} |
|
|
|
|
|
|
|
Serial.printf("MP3 done\n"); |
|
|
|
strcpy(titleStr, "___"); |
|
|
|
|
|
|
|
playing = false; |
|
|
|
|
|
|
|
if (mp3) { |
|
|
|
mp3->stop(); |
|
|
|
delete mp3; |
|
|
|
mp3 = NULL; |
|
|
|
if (decoder) { |
|
|
|
decoder->stop(); |
|
|
|
delete decoder; |
|
|
|
decoder = NULL; |
|
|
|
} |
|
|
|
if (buff) { |
|
|
|
buff->close(); |
|
|
|