4#include "AudioLogger.h"
5#include "AudioTools/Disk/AudioSource.h"
6#include "AudioTools/Disk/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;
43#ifdef USE_SD_SUPPORTS_SPI
45 AudioSourceIdxSD(
const char *startFilePath,
const char *ext,
int chipSelect, SPIClass &spiInstance,
bool setupIndex=
true) {
46 start_path = startFilePath;
48 setup_index = setupIndex;
59 LOGW(
"SD.begin cs=%d failed", cs);
67 idx.begin(start_path, extension, file_name_pattern, setup_index);
78 LOGI(
"nextStream: %d", offset);
83 LOGI(
"selectStream: %d",
index);
85 file_name = idx[
index];
86 if (file_name==
nullptr)
return nullptr;
87 LOGI(
"Using file %s", file_name);
88 file = SD.open(file_name);
89 return file ? &file :
nullptr;
95 file_name = file.name();
96 LOGI(
"-> selectStream: %s", path);
97 return file ? &file :
nullptr;
108 const char *
toStr() {
return file_name; }
114 virtual void setPath(
const char *p) { start_path = p; }
117 long size() {
return idx.size();}
130#if defined(USE_SD_NO_NS)
133 SDIndex<fs::SDFS,fs::File> idx{SD};
137 const char *file_name;
138 const char *extension =
nullptr;
139 const char *start_path =
nullptr;
140 const char *file_name_pattern =
"*";
141 bool setup_index =
true;
142 bool is_sd_setup =
false;
143 SPIClass *p_spi =
nullptr;
147#ifdef USE_SD_SUPPORTS_SPI
148 return SD.begin(cs, *p_spi);