Skip to content

Commit ec4a873

Browse files
committed
support for selectStream(int index) in AudioSourceSdFat and AudioSourceCallback
1 parent ee8b03a commit ec4a873

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/AudioTools/AudioPlayer.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace audio_tools {
4040
virtual Stream* nextStream(int offset) = 0;
4141

4242
/// Returns next audio stream
43-
virtual Stream* selectStream(int station) {
43+
virtual Stream* selectStream(int index) {
4444
LOGE("Not Supported!");
4545
return nullptr;
4646
}
@@ -80,6 +80,12 @@ namespace audio_tools {
8080
return nextStreamCallback == nullptr ? nullptr : nextStreamCallback();
8181
}
8282

83+
/// Returns next audio stream
84+
virtual Stream* selectStream(int index) {
85+
return indexStreamCallback == nullptr ? nullptr : indexStreamCallback(index);
86+
}
87+
88+
8389
void setCallbackOnStart(void (*callback)()) {
8490
onStartCallback = callback;
8591
}
@@ -88,9 +94,14 @@ namespace audio_tools {
8894
nextStreamCallback = callback;
8995
}
9096

97+
void setCallbackSelectStream(Stream* (*callback)(int idx)) {
98+
indexStreamCallback = callback;
99+
}
100+
91101
protected:
92102
void (*onStartCallback)() = nullptr;
93103
Stream* (*nextStreamCallback)() = nullptr;
104+
Stream* (*indexStreamCallback)(int index) = nullptr;
94105

95106
};
96107

@@ -140,6 +151,14 @@ namespace audio_tools {
140151
return file ? &file : nullptr;
141152
}
142153

154+
virtual Stream* selectStream(int index) {
155+
file.close();
156+
file = getFile(start_path, index);
157+
file.getName(file_name, MAX_FILE_LEN);
158+
LOGI("-> nextStream: '%s'", file_name);
159+
return file ? &file : nullptr;
160+
}
161+
143162
/// Defines the regex filter criteria for selecting files. E.g. ".*Bob Dylan.*"
144163
void setFileFilter(const char* filter) {
145164
file_name_pattern = filter;

0 commit comments

Comments
 (0)