@@ -230,12 +230,9 @@ class AudioSourceVector : public AudioSource {
230
230
TRACED ();
231
231
if (path == nullptr ) return nullptr ;
232
232
233
- // Find the file by path
234
- for (int i = 0 ; i < (int )files.size (); i++) {
235
- Str fullPath = getFullPath (i);
236
- if (fullPath.equals (path)) {
237
- return selectStream (i);
238
- }
233
+ int idx = indexOf (path);
234
+ if (idx >= 0 ) {
235
+ return selectStream (idx);
239
236
}
240
237
241
238
LOGE (" File not found: %s" , path);
@@ -247,6 +244,20 @@ class AudioSourceVector : public AudioSource {
247
244
return current_index;
248
245
}
249
246
247
+ // / Find index of file by path
248
+ int indexOf (const char * path) {
249
+ if (path == nullptr ) return -1 ;
250
+
251
+ // Find the file by path
252
+ for (int i = 0 ; i < (int )files.size (); i++) {
253
+ Str fullPath = getFullPath (i);
254
+ if (fullPath.equals (path)) {
255
+ return i;
256
+ }
257
+ }
258
+ return -1 ;
259
+ }
260
+
250
261
// / Add a file with full path (path and name will be separated automatically)
251
262
void addName (const char * nameWithPath) {
252
263
TRACED ();
@@ -326,6 +337,11 @@ class AudioSourceVector : public AudioSource {
326
337
}
327
338
return nullptr ;
328
339
}
340
+
341
+ // / provides the name at the given index
342
+ const char * name (int index){
343
+ return getFullPath (index).c_str ();
344
+ }
329
345
330
346
protected:
331
347
Vector<FileEntry> files;
@@ -464,12 +480,9 @@ class AudioSourceArray : public AudioSource {
464
480
TRACED ();
465
481
if (path == nullptr ) return nullptr ;
466
482
467
- // Find the file by path
468
- for (int i = 0 ; i < (int )array_size; i++) {
469
- const char * filePath = file_array[i];
470
- if (StrView (path).equals (filePath)) {
471
- return selectStream (i);
472
- }
483
+ int idx = indexOf (path);
484
+ if (idx >= 0 ) {
485
+ return selectStream (idx);
473
486
}
474
487
475
488
LOGE (" File not found: %s" , path);
@@ -481,6 +494,20 @@ class AudioSourceArray : public AudioSource {
481
494
return current_index;
482
495
}
483
496
497
+ // / Find index of file by path
498
+ int indexOf (const char * path) {
499
+ if (path == nullptr ) return -1 ;
500
+
501
+ // Find the file by path
502
+ for (int i = 0 ; i < (int )array_size; i++) {
503
+ const char * filePath = file_array[i];
504
+ if (filePath && StrView (path).equals (filePath)) {
505
+ return i;
506
+ }
507
+ }
508
+ return -1 ;
509
+ }
510
+
484
511
// / Set the array of file names
485
512
template <size_t N>
486
513
void setArray (const char * (&nameArray)[N]) {
@@ -533,7 +560,13 @@ class AudioSourceArray : public AudioSource {
533
560
}
534
561
return nullptr ;
535
562
}
563
+
564
+ // / provides the name at the given index
565
+ const char * name (int index){
566
+ return getFilePath (index);
567
+ }
536
568
569
+
537
570
protected:
538
571
const char * const * file_array = nullptr ; // Pointer to array of const char*
539
572
size_t array_size = 0 ;
0 commit comments