You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor callbacks so they can be set and cleared at runtime (#70)
* Refactor callbacks so they can be set and cleared at runtime
* Update the examples in README.md
* Make all codec names < 5 chars
* Shorten and camelCase member function names
* Update README.md
Copy file name to clipboardExpand all lines: README.md
+61-46Lines changed: 61 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ Also plays mp3 and ogg files from sdcard or any mounted filesystem.
14
14
15
15
While this [PR](https://github.com/baldram/ESP_VS1053_Library/pull/119) is waiting to be merged in the `baldram/ESP_VS1053_Library` repo, you have to use the this [fork](baldram/ESP_VS1053_Library) to be able to compile the `master` branch.
16
16
17
-
Use the [latest Arduino ESP32 core version](https://github.com/espressif/arduino-esp32/releases/latest).
17
+
Use the [latest Arduino ESP32 core version](https://github.com/espressif/arduino-esp32/releases/latest) for Arduino IDE or the corresponding [PIOArduino release](https://github.com/pioarduino/platform-espressif32/releases/latest) if yuou use PlatformIO in VSCode.
18
18
19
19
## Example: play a stream
20
20
```c++
@@ -37,24 +37,38 @@ ESP32_VS1053_Stream stream;
37
37
constchar* SSID = "xxx";
38
38
constchar* PSK = "xxx";
39
39
40
-
//called when codec is detected
40
+
//Called when codec is detected
41
41
voidcodecCallBack(const char *codec)
42
42
{
43
43
Serial.printf("codec: %s\n", codec);
44
44
}
45
45
46
-
// called when bitrate is detected (cbr) and changes (vbr)
46
+
// Called when bitrate is detected (cbr) and changes (vbr)
47
47
void bitrateCallback(uint32_t bitrate)
48
48
{
49
49
Serial.printf("bitrate: %lu kbps\n", bitrate);
50
50
}
51
51
52
-
void setup() {
53
-
Serial.begin(115200);
52
+
// Called when a stream has an ICY name header set
53
+
void stationCallback(const char *name)
54
+
{
55
+
Serial.printf("station: %s\n", name);
56
+
}
54
57
55
-
while (!Serial)
56
-
delay(10);
58
+
// Called when stream metadata is available
59
+
void infoCallback(const char *info)
60
+
{
61
+
Serial.printf("info: %s\n", info);
62
+
}
57
63
64
+
// Called on end-of-file
65
+
void eofCallback(const char *url)
66
+
{
67
+
Serial.printf("eof: %s\n", url);
68
+
}
69
+
70
+
void setup() {
71
+
Serial.begin(115200);
58
72
Serial.println("\n\nVS1053 Radio Streaming Example\n");
59
73
60
74
// Connect to Wi-Fi
@@ -76,16 +90,26 @@ void setup() {
76
90
Serial.println("Decoder not running - system halted");
77
91
while (1) delay(100);
78
92
}
79
-
Serial.println("VS1053 running - starting radio stream");
80
93
81
-
// Setup the codec callback
82
-
stream.setCodecCallback(codecCallBack);
94
+
// Set the codec callback
95
+
stream.setCodecCB(codecCallBack);
83
96
84
-
// Setup the bitrate callback
85
-
stream.setBitrateCallback(bitrateCallback);
97
+
// Set the bitrate callback
98
+
stream.setBitrateCB(bitrateCallback);
99
+
100
+
// Set the station name callback
101
+
stream.setStationCB(stationCallback);
102
+
103
+
// Set the stream metadata callback
104
+
stream.setInfoCB(infoCallback);
105
+
106
+
// Set the EOF callback
107
+
stream.setEofCB(eofCallback);
108
+
109
+
Serial.println("VS1053 running - starting radio stream");
0 commit comments