4 #include "AudioLogger.h"
5 #include "AudioBasic/StrExt.h"
6 #include "AudioTools/AudioSource.h"
7 #include "AudioLibs/SDIndex.h"
35 AudioSourceIdxSD(
const char *startFilePath =
"/",
const char *ext =
".mp3",
int chipSelect = PIN_CS,
bool setupIndex=
true) {
36 start_path = startFilePath;
38 setup_index = setupIndex;
45 while (!SD.begin(cs)) {
46 LOGW(
"SD.begin cs=%d failed", cs);
51 idx.begin(start_path, exension, file_name_pattern, setup_index);
61 LOGI(
"nextStream: %d", offset);
66 LOGI(
"selectStream: %d",
index);
68 file_name = idx[
index];
69 if (file_name==
nullptr)
return nullptr;
70 LOGI(
"Using file %s", file_name);
71 file = SD.open(file_name);
72 return file ? &file :
nullptr;
78 file_name = file.name();
79 LOGI(
"-> selectStream: %s", path);
80 return file ? &file :
nullptr;
91 const char *
toStr() {
return file_name; }
97 virtual void setPath(
const char *p) { start_path = p; }
100 long size() {
return idx.size();}
103 #if defined(USE_SD_NO_NS)
106 SDIndex<fs::SDFS,fs::File> idx{SD};
110 const char *file_name;
111 const char *exension =
nullptr;
112 const char *start_path =
nullptr;
113 const char *file_name_pattern =
"*";
114 bool setup_index =
true;
115 bool is_sd_setup =
false;