Skip to content

Update from 3.4.2 to 3.4.3 audio.connecttoFS() always return false at the firs time. #1214

@VaAndCob

Description

@VaAndCob

Firstly, I have to thank for this library. love it.
I upgraded from 3.4.2 to 3.4.3
Found that many streaming has better quality, there is no / less chopping and stuttering.

but I have problemw with audio.connecttoFS function

  if (!audio.connecttoFS(SD, filePath.c_str())) {
      log_w("Failed to open file: %s", filePath.c_str());
      audio.connecttoFS(LittleFS, "/audio/error.mp3");
    }

before update, audio.connecttoFS will always return true, but last update will always return false, anyway the music still plays correctly.

So I fixed the source code here. I'm not sure if it's correct, but it works.

bool Audio::connecttoFS(fs::FS& fs, const char* path, int32_t fileStartTime) {

    xSemaphoreTakeRecursive(mutex_playAudioData, 0.3 * configTICK_RATE_HZ);
    ps_ptr<char> c_path;
    ps_ptr<char> audioPath;
    bool         res = false;
    m_fileStartTime = fileStartTime;
    m_codec = CODEC_NONE;

    if (!path) {
        AUDIO_LOG_ERROR("file path is not set");
        goto exit;
    } // guard
    c_path.copy_from(path); // copy from path
    c_path.trim();
    if (!c_path.contains(".")) {
        AUDIO_LOG_ERROR("No file extension found");
        goto exit;
    } // guard
    setDefaults(); // free buffers an set defaults

    if (c_path.ends_with_icase(".mp3")) m_codec = CODEC_MP3;
    if (c_path.ends_with_icase(".m4a")) m_codec = CODEC_M4A;
    if (c_path.ends_with_icase(".aac")) m_codec = CODEC_AAC;
    if (c_path.ends_with_icase(".wav")) m_codec = CODEC_WAV;
    if (c_path.ends_with_icase(".flac")) m_codec = CODEC_FLAC;
    if (c_path.ends_with_icase(".opus")) m_codec = CODEC_OGG;
    if (c_path.ends_with_icase(".ogg")) m_codec = CODEC_OGG;
    if (c_path.ends_with_icase(".oga")) m_codec = CODEC_OGG;

    if (m_codec == CODEC_OGG) m_f_ogg = true;
    if (m_codec == CODEC_NONE) { // guard
        int dotPos = c_path.last_index_of('.');
        AUDIO_LOG_WARN("The %s format is not supported", path + dotPos);
        goto exit;
    }

    if (!c_path.starts_with("/")) c_path.insert("/", 0);

    if (!fs.exists(c_path.get())) {
        AUDIO_LOG_WARN("file not found: %s", c_path.get());
        goto exit;
    }
    info(*this, evt_info, "Reading file: \"%s\"", c_path.get());
    m_audiofile = fs.open(c_path.get());
    m_dataMode = AUDIO_LOCALFILE;
    m_audioFileSize = m_audiofile.size();
    m_f_running = true;
    res = true;<----- ADD THIS LINE
exit:
    xSemaphoreGiveRecursive(mutex_playAudioData);
    return res;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions