Skip to content

Commit 7811008

Browse files
authored
Merge pull request #50 from podaen/main
Set path URLstream
2 parents c5837e8 + d81f614 commit 7811008

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

src/AudioTools/AudioPlayer.h

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ namespace audio_tools {
5959
return selectStream(index);
6060
}
6161

62-
/// same as selectStream - I just prefer this name
63-
virtual Stream* selectStream(char* path, char* fileName) {
64-
return selectStream(path,fileName);
62+
/// Returns audio stream by path
63+
virtual Stream* selectStream(char* path) {
64+
return selectStream(path);
6565
}
6666

6767
/// Sets the timeout which is triggering to move to the next stream. - the default value is 500 ms
@@ -216,10 +216,10 @@ namespace audio_tools {
216216
return file ? &file : nullptr;
217217
}
218218

219-
virtual Stream* selectStream(char* path, char* fileName) override {
219+
virtual Stream* selectStream(char* path) override {
220220
file.close();
221-
file = getFileByPath(path, fileName);
222-
LOGW("-> selectStream: %s%s", path, fileName);
221+
file = getFileByPath(path);
222+
LOGW("-> selectStream: %s", path);
223223
return file ? &file : nullptr;
224224
}
225225

@@ -282,9 +282,15 @@ namespace audio_tools {
282282
return result;
283283
}
284284

285-
AudioFile getFileByPath(char* path, char* fileName) {
285+
AudioFile getFileByPath(char* path) {
286286
AudioFile dir;
287-
if (!dir.open(path)) {//("/21/" , "001.mp3")
287+
Str inPath(path);
288+
StrExt strPath;
289+
StrExt strfileName;
290+
int pos = inPath.lastIndexOf("/") + 1;
291+
strPath.substring(path, 0, pos);
292+
strfileName.substring(path, pos, inPath.length());
293+
if (!dir.open(strPath.c_str())) {//("/21/" , "001.mp3")
288294
LOGE("directory: %s not open", path);
289295
}
290296
else
@@ -294,12 +300,12 @@ namespace audio_tools {
294300
}
295301
else
296302
{
297-
if (!file.open(&dir, fileName, O_RDWR)) {
303+
if (!file.open(&dir, strfileName.c_str(), O_RDWR)) {
298304
LOGE("file: %s not open", path);
299305
}
300306
else
301307
{
302-
LOGD("-> getFileByPath: '%s': %d", path, fileName);
308+
LOGD("-> getFileByPath: '%s': %d", path, strfileName.c_str());
303309
}
304310
}
305311
}
@@ -415,6 +421,15 @@ namespace audio_tools {
415421
return selectStream(pos);
416422
}
417423

424+
/// Opens the selected url
425+
Stream* selectStream(char* path) override {
426+
LOGI("selectStream: %s", path);
427+
if (started) actual_stream->end();
428+
actual_stream->begin(path, mime);
429+
started = true;
430+
return actual_stream;
431+
}
432+
418433
int index() {
419434
return pos;
420435
}
@@ -647,10 +662,10 @@ namespace audio_tools {
647662
}
648663

649664
/// moves to selected file
650-
virtual bool setPath(char* path, char* fileName) {
665+
virtual bool setPath(char* path) {
651666
LOGD(LOG_METHOD);
652667
previous_stream = false;
653-
active = setStream(p_source->selectStream(path, fileName));
668+
active = setStream(p_source->selectStream(path));
654669
return active;
655670
}
656671

0 commit comments

Comments
 (0)