Skip to content

Commit 7dfa8c8

Browse files
committed
simplify AudioSourceCallback
1 parent ed34cd5 commit 7dfa8c8

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/AudioTools/AudioPlayer.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,17 @@ namespace audio_tools {
7979
if (onStartCallback != nullptr) onStartCallback();
8080
};
8181

82-
/// Returns next stream
82+
/// Returns next (with positive index) or previous stream (with negative index)
8383
virtual Stream* nextStream(int offset) {
8484
LOGD(LOG_METHOD);
8585
return nextStreamCallback == nullptr ? nullptr : nextStreamCallback();
8686
}
8787

88-
/// Returns selected audio stream
88+
/// Returns selected audio stream
8989
virtual Stream* selectStream(int index) {
9090
return indexStreamCallback == nullptr ? nullptr : indexStreamCallback(index);
9191
}
9292

93-
/// Returns previous stream
94-
virtual Stream* previousStream(int offset) {
95-
LOGD(LOG_METHOD);
96-
return previousStreamCallback == nullptr ? nullptr : previousStreamCallback();
97-
}
98-
9993
void setCallbackOnStart(void (*callback)()) {
10094
onStartCallback = callback;
10195
}
@@ -108,15 +102,11 @@ namespace audio_tools {
108102
indexStreamCallback = callback;
109103
}
110104

111-
void setCallbackPreviousStream(Stream* (*callback)()) {
112-
previousStreamCallback = callback;
113-
}
114105

115106
protected:
116107
void (*onStartCallback)() = nullptr;
117108
Stream* (*nextStreamCallback)() = nullptr;
118109
Stream* (*indexStreamCallback)(int index) = nullptr;
119-
Stream* (*previousStreamCallback)() = nullptr;
120110
};
121111

122112
#ifdef USE_SDFAT
@@ -169,8 +159,12 @@ namespace audio_tools {
169159
}
170160

171161
virtual Stream* selectStream(int index) {
162+
pos = index;
163+
if (pos<0){
164+
pos = 0;
165+
}
172166
file.close();
173-
file = getFile(start_path, index);
167+
file = getFile(start_path, pos);
174168
file.getName(file_name, MAX_FILE_LEN);
175169
LOGI("-> selectStream: '%s'", file_name);
176170
return file ? &file : nullptr;

0 commit comments

Comments
 (0)