Skip to content

Commit 84d530a

Browse files
committed
2 parents 15f16af + 0a7d419 commit 84d530a

File tree

4 files changed

+53
-25
lines changed

4 files changed

+53
-25
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ As “Audio Sources” we will have e.g.:
2020
- Analog Microphones – [AnalogAudioStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_analog_audio_stream.html)
2121
- Digital Microphones – [I2SStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_i2_s_stream.html)
2222
- Files on the Internet – [URLStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_u_r_l_stream.html)
23+
- Streaming Internet Radios - [ICYStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_i_c_y_stream.html)
2324
- Generated Sound – [GeneratedSoundStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_generated_sound_stream.html)
2425
- Mobile Phone A2DP Bluetooth – [A2DPStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_a2_d_p_stream.html)
2526
- Binary Data in Flash Memory – [MemoryStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_memory_stream.html)

src/AudioHttp/ICYStream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace audio_tools {
1111
* @brief Icecast/Shoutcast Audio Stream which splits the data into metadata and audio data. The Audio data is provided via the
1212
* regular stream functions. The metadata is handled with the help of the MetaDataICY state machine and provided via a callback method.
1313
*
14-
* This is basically just a URLStreamD with the metadata turned on.
14+
* This is basically just a URLStream with the metadata turned on.
1515
*
1616
* @author Phil Schatzmann
1717
* @copyright GPLv3

src/AudioHttp/ICYStreamESP32.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ namespace audio_tools {
88

99
/**
1010
* @brief ICYStream implementation for the ESP32 based on a FreeRTOS task
11+
* This is a Icecast/Shoutcast Audio Stream which splits the data into metadata and audio data. The Audio data is provided via the
12+
* regular stream functions. The metadata is handled with the help of the MetaDataICY state machine and provided via a callback method.
13+
*
14+
* This is basically just a URLStream with the metadata turned on.
15+
*
1116
* @author Phil Schatzmann
1217
* @copyright GPLv3
1318
*/

src/AudioTools/AudioPlayer.h

Lines changed: 46 additions & 24 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
}
@@ -581,19 +596,22 @@ namespace audio_tools {
581596
p_source->begin();
582597
meta_out.begin();
583598

584-
p_input_stream = p_source->selectStream(index);
585-
if (p_input_stream != nullptr) {
586-
if (meta_active) {
587-
copier.setCallbackOnWrite(decodeMetaData, this);
599+
if (index >= 0) {
600+
p_input_stream = p_source->selectStream(index);
601+
if (p_input_stream != nullptr) {
602+
if (meta_active) {
603+
copier.setCallbackOnWrite(decodeMetaData, this);
604+
}
605+
copier.begin(*p_out_decoding, *p_input_stream);
606+
timeout = millis() + p_source->timeoutAutoNext();
607+
active = isActive;
608+
result = true;
609+
}
610+
else {
611+
LOGW("-> begin: no data found");
612+
active = isActive;
613+
result = false;
588614
}
589-
copier.begin(*p_out_decoding, *p_input_stream);
590-
timeout = millis() + p_source->timeoutAutoNext();
591-
active = isActive;
592-
result = true;
593-
}
594-
else {
595-
LOGW("-> begin: no data found");
596-
active = isActive;
597615
}
598616
return result;
599617
}
@@ -647,10 +665,10 @@ namespace audio_tools {
647665
}
648666

649667
/// moves to selected file
650-
virtual bool setPath(char* path, char* fileName) {
668+
virtual bool setPath(char* path) {
651669
LOGD(LOG_METHOD);
652670
previous_stream = false;
653-
active = setStream(p_source->selectStream(path, fileName));
671+
active = setStream(p_source->selectStream(path));
654672
return active;
655673
}
656674

@@ -713,6 +731,10 @@ namespace audio_tools {
713731
// reset timeout
714732
timeout = millis() + p_source->timeoutAutoNext();
715733
}
734+
else
735+
{
736+
active = false;
737+
}
716738
// move to next stream after timeout
717739
if (p_input_stream == nullptr || millis() > timeout) {
718740
if (autonext) {

0 commit comments

Comments
 (0)