//----------------------------------------------------------------- QList<QFileInfo> Utils::findFiles(const QDir initialDir, const QStringList extensions, bool with_subdirectories, const std::function<bool (const QFileInfo &)> &condition) { QList<QFileInfo> otherFilesFound, mp3FilesFound; auto startingDir = initialDir; startingDir.setFilter(QDir::Files | QDir::Dirs | QDir::NoDot | QDir::NoDotDot); startingDir.setNameFilters(extensions); auto flag = (with_subdirectories ? QDirIterator::Subdirectories : QDirIterator::NoIteratorFlags); QDirIterator it(startingDir, flag); while (it.hasNext()) { it.next(); auto info = it.fileInfo(); if(!condition(info)) continue; auto extension = info.absoluteFilePath().split('.').last().toLower(); if (isMP3File(info)) { mp3FilesFound << info; } else { otherFilesFound << info; } } return mp3FilesFound + otherFilesFound; }
boolean Adafruit_VS1053_FilePlayer::startPlayingFile(const char *trackname) { // reset playback sciWrite(VS1053_REG_MODE, VS1053_MODE_SM_LINE1 | VS1053_MODE_SM_SDINEW); // resync sciWrite(VS1053_REG_WRAMADDR, 0x1e29); sciWrite(VS1053_REG_WRAM, 0); currentTrack = SD.open(trackname); if (!currentTrack) { return false; } // We know we have a valid file. Check if .mp3 // If so, check for ID3 tag and jump it if present. if (isMP3File(trackname)) { currentTrack.seek(mp3_ID3Jumper(currentTrack)); } // don't let the IRQ get triggered by accident here noInterrupts(); // As explained in datasheet, set twice 0 in REG_DECODETIME to set time back to 0 sciWrite(VS1053_REG_DECODETIME, 0x00); sciWrite(VS1053_REG_DECODETIME, 0x00); playingMusic = true; // wait till its ready for data while (! readyForData() ) { #if defined(ESP8266) yield(); #endif } // fill it up! while (playingMusic && readyForData()) { feedBuffer(); } // ok going forward, we can use the IRQ interrupts(); return true; }