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