diff --git a/tasmota/xdrv_42_i2s_audio.ino b/tasmota/xdrv_42_i2s_audio.ino index 4a3bd91b0..aa0979797 100644 --- a/tasmota/xdrv_42_i2s_audio.ino +++ b/tasmota/xdrv_42_i2s_audio.ino @@ -54,6 +54,8 @@ AudioFileSourceID3 *id3; AudioGeneratorMP3 *decoder = NULL; void *mp3ram = NULL; +#define I2SAUDIO_TASK_STACK_SIZE 8192 + #ifdef ESP8266 const int preallocateBufferSize = 5*1024; @@ -189,6 +191,7 @@ void sayTime(int hour, int minutes, AudioGeneratorTalkie *talkie) { } else { talkie->say(spA_M_, sizeof(spA_M_)); } + out->stop(); delete talkie; TTGO_PWR_OFF } @@ -293,7 +296,7 @@ void Webradio(const char *url) { retryms = millis() + 2000; } - xTaskCreatePinnedToCore(mp3_task2, "MP3-2", 8192, NULL, 3, &mp3_task_h, 1); + xTaskCreatePinnedToCore(mp3_task2, "MP3-2", I2SAUDIO_TASK_STACK_SIZE, NULL, 3, &mp3_task_h, 1); } void mp3_task2(void *arg){ @@ -373,25 +376,27 @@ void Play_mp3(const char *path) { } file = new AudioFileSourceFS(*fsp,path); - id3 = new AudioFileSourceID3(file); + if (file->isOpen()) { + id3 = new AudioFileSourceID3(file); - if (mp3ram) { - mp3 = new AudioGeneratorMP3(mp3ram, preallocateCodecSize); - } else { - mp3 = new AudioGeneratorMP3(); - } - mp3->begin(id3, out); + if (mp3ram) { + mp3 = new AudioGeneratorMP3(mp3ram, preallocateCodecSize); + } else { + mp3 = new AudioGeneratorMP3(); + } + mp3->begin(id3, out); - if (I2S_Task) { - xTaskCreatePinnedToCore(mp3_task, "MP3", 8192, NULL, 3, &mp3_task_h, 1); - } else { - while (mp3->isRunning()) { - if (!mp3->loop()) { - mp3->stop(); - mp3_delete(); - break; + if (I2S_Task) { + xTaskCreatePinnedToCore(mp3_task, "MP3", I2SAUDIO_TASK_STACK_SIZE, NULL, 3, &mp3_task_h, 1); + } else { + while (mp3->isRunning()) { + if (!mp3->loop()) { + mp3->stop(); + mp3_delete(); + break; + } + OsWatchLoop(); } - OsWatchLoop(); } }