schreibfaul1 / ESP32-audioI2S

Play mp3 files from SD via I2S
GNU General Public License v3.0
1.14k stars 291 forks source link

Calling audio.getAudioFileDuration() after calling audio.connecttoFS(); multiple times causes it to hang #906

Open ra0943-VK3ACH opened 3 days ago

ra0943-VK3ACH commented 3 days ago

This is gonna sound dumb but whenever I call my PlayItem function for a 2nd time the loop hangs. If I remove the line CurrentSongFileDuration = 0; it runs fine. I took a quick look at the library and I couldnt see anything wrong

void Player::PlayItem(int queueIndex){
    Serial.println("Chagne index");
    CurrentlyPlayingIndex = queueIndex;
    audio.connecttoFS(SD_MMC, Queue[queueIndex].c_str());
    CurrentSongFileDuration = 0;
}

void Player::AudioLoop(){
    audio.loop();
    vTaskDelay(1);
    if(audio.isRunning()){
        int currentTime = audio.getAudioCurrentTime();
        if(CurrentSongFileDuration == 0){
            CurrentSongFileDuration = audio.getAudioFileDuration();
        }
        if(currentTime != previousCurrentTime){
            DrawNowPlayingTime(CurrentSongFileDuration, currentTime);
            previousCurrentTime = currentTime;
        }
    }

}
schreibfaul1 commented 2 days ago

It is not possible to analyse the audio file in advance with the ESP32. The ESP32 is too slow for this. After several audio frames have been played, the average value can be calculated with a variable bit rate. This allows the total playing time of the audio file to be calculated. The longer the file plays, the more accurate the values are.