earlephilhower / ESP8266Audio

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
1.98k stars 432 forks source link

use esp32c3 After the sound stops, wait 4-5 minutes. #667

Open kangz543g opened 4 months ago

kangz543g commented 4 months ago

int outputUrlToSpeaker(String url) { static int lastms = 0; unsigned long startTime = millis(); // 현재 시간 기록

file = new AudioFileSourceHTTPStream(url.c_str());
buff = new AudioFileSourceBuffer(file, preallocateBuffer, preallocateBufferSize);
mp3 = new AudioGeneratorMP3();
mp3->begin(buff, out);

digitalWrite(LED_audio, HIGH);

while (mp3->isRunning() && millis() - startTime < 10000) { // 현재 시간이 시작 시간으로부터 10초 이내일 때까지 루프 실행
    if (!mp3->loop()) {
        mp3->stop();    <---- After the sound stops, wait 4-5 minutes.   problem????
        if (file != nullptr) {
          delete file;
          file = nullptr;
        }
        digitalWrite(LED_audio, LOW);
        delete out;
        delete mp3;
        return -1; // MP3가 중간에 중단되었음을 나타냄
    }

    // 1초마다 시간 출력
    if (millis() - lastms > 1000) {
        lastms = millis();
        Serial.printf("Running for %d ms...\n", lastms);
        Serial.flush();
    }
}

return 0; // 성공적으로 MP3가 종료됨을 나타냄

}