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;
58 LOGW(
"SD.begin cs=%d failed", cs);
63 idx.begin(start_path, extension, file_name_pattern, setup_index);
73 LOGI(
"nextStream: %d", offset);
78 LOGI(
"selectStream: %d",
index);
80 file_name = idx[
index];
81 if (file_name==
nullptr)
return nullptr;
82 LOGI(
"Using file %s", file_name);
83 file = SD.open(file_name);
84 return file ? &file :
nullptr;
90 file_name = file.name();
91 LOGI(
"-> selectStream: %s", path);
92 return file ? &file :
nullptr;
103 const char *
toStr() {
return file_name; }
109 virtual void setPath(
const char *p) { start_path = p; }
112 long size() {
return idx.size();}
125#if defined(USE_SD_NO_NS)
128 SDIndex<fs::SDFS,fs::File> idx{SD};
132 const char *file_name;
133 const char *extension =
nullptr;
134 const char *start_path =
nullptr;
135 const char *file_name_pattern =
"*";
136 bool setup_index =
true;
137 bool is_sd_setup =
false;
138 SPIClass *p_spi =
nullptr;
142#ifdef USE_SD_SUPPORTS_SPI
143 return SD.begin(cs, *p_spi);