@@ -59,6 +59,11 @@ namespace audio_tools {
59
59
return selectStream (index);
60
60
}
61
61
62
+ // / same as selectStream - I just prefer this name
63
+ virtual Stream* selectStream (char * path, char * fileName) {
64
+ return selectStream (path,fileName);
65
+ }
66
+
62
67
// / Sets the timeout which is triggering to move to the next stream. - the default value is 500 ms
63
68
virtual void setTimeoutAutoNext (int millisec) {
64
69
timeout_auto_next_value = millisec;
@@ -149,7 +154,7 @@ namespace audio_tools {
149
154
typedef File AudioFile;
150
155
#elif SD_FAT_TYPE == 1
151
156
typedef SdFat32 AudioFs;
152
- typedef File32 AudioDir;
157
+ // typedef File32 AudioDir;
153
158
typedef File32 AudioFile;
154
159
#elif SD_FAT_TYPE == 2
155
160
typedef SdExFat AudioFs;
@@ -205,12 +210,19 @@ namespace audio_tools {
205
210
virtual Stream* selectStream (int index) override {
206
211
idx_pos = index<0 ? 0 : index;
207
212
file.close ();
208
- file = getFile (start_path, idx_pos);
213
+ file = getFileByPos (start_path, idx_pos);
209
214
file.getName (file_name, MAX_FILE_LEN);
210
215
LOGW (" -> selectStream: %d '%s'" , idx_pos, file_name);
211
216
return file ? &file : nullptr ;
212
217
}
213
218
219
+ virtual Stream* selectStream (char * path, char * fileName) override {
220
+ file.close ();
221
+ file = getFileByPath (path, fileName);
222
+ LOGW (" -> selectStream: %s%s" , path, fileName);
223
+ return file ? &file : nullptr ;
224
+ }
225
+
214
226
// / Defines the regex filter criteria for selecting files. E.g. ".*Bob Dylan.*"
215
227
void setFileFilter (const char * filter) {
216
228
file_name_pattern = (char *)filter;
@@ -251,7 +263,7 @@ namespace audio_tools {
251
263
}
252
264
253
265
// / Determines the file at the indicated index (starting with 0)
254
- AudioFile getFile (const char * dirStr, int pos) {
266
+ AudioFile getFileByPos (const char * dirStr, int pos) {
255
267
AudioFile dir;
256
268
AudioFile result;
257
269
if (sd.exists (dirStr)){
@@ -270,6 +282,31 @@ namespace audio_tools {
270
282
return result;
271
283
}
272
284
285
+ AudioFile getFileByPath (char * path, char * fileName) {
286
+ AudioFile dir;
287
+ if (!dir.open (path)) {// ("/21/" , "001.mp3")
288
+ LOGE (" directory: %s not open" , path);
289
+ }
290
+ else
291
+ {
292
+ if (!dir.isDir ()) {
293
+ LOGE (" directory: %s is not dictory" , path);
294
+ }
295
+ else
296
+ {
297
+ if (!file.open (&dir, fileName, O_RDWR)) {
298
+ LOGE (" file: %s not open" , path);
299
+ }
300
+ else
301
+ {
302
+ LOGD (" -> getFileByPath: '%s': %d" , path, fileName);
303
+ }
304
+ }
305
+ }
306
+ dir.close ();
307
+ return file;
308
+ }
309
+
273
310
// / Recursively walk the directory tree to find the file at the indicated pos.
274
311
void getFileAtIndex (AudioFile dir, size_t pos, size_t & idx, AudioFile& result) {
275
312
LOGD (" %s: %d" , LOG_METHOD, idx);
@@ -308,6 +345,7 @@ namespace audio_tools {
308
345
}
309
346
}
310
347
}
348
+
311
349
};
312
350
313
351
#endif
@@ -608,6 +646,14 @@ namespace audio_tools {
608
646
return active;
609
647
}
610
648
649
+ // / moves to selected file
650
+ virtual bool setPath (char * path, char * fileName) {
651
+ LOGD (LOG_METHOD);
652
+ previous_stream = false ;
653
+ active = setStream (p_source->selectStream (path, fileName));
654
+ return active;
655
+ }
656
+
611
657
// / moves to previous file
612
658
virtual bool previous (int offset=1 ) {
613
659
LOGD (LOG_METHOD);
0 commit comments