@@ -34,46 +34,6 @@ void shufflePlaylist() {
3434 }
3535}
3636
37- /*
38- * The same thing as saving and loading playlist can be achieved using JSON API saved in a preset.
39- *
40- void deserializePlaylist() {
41- DynamicJsonDocument doc(JSON_BUFFER_SIZE);
42-
43- DEBUG_PRINTLN(F("Reading playlist from /playlist.json..."));
44-
45- if (!readObjectFromFile("/playlist.json", nullptr, &doc)) return; //if file does not exist just exit
46-
47- JsonObject playlist = doc[F("playlist")];
48- if (!playlist.isNull()) loadPlaylist(playlist);
49- }
50-
51-
52- void serializePlaylist() {
53- DynamicJsonDocument doc(JSON_BUFFER_SIZE/8); // we don't need big buffer (>1k is ok)
54-
55- DEBUG_PRINTLN(F("Writing playlist to /playlist.json..."));
56-
57- PlaylistEntry* entries = reinterpret_cast<PlaylistEntry*>(playlistEntries);
58-
59- JsonObject playlist = doc.createNestedObject(F("playlist"));
60- JsonArray ps = playlist.createNestedArray(F("ps"));
61- JsonArray dur = playlist.createNestedArray(F("dur"));
62- JsonArray tr = playlist.createNestedArray(F("transition"));
63- for (uint8_t i=0; i<playlistLen; i++) {
64- ps.add(entries[i].preset);
65- dur.add(entries[i].dur);
66- tr.add(entries[i].tr);
67- }
68- playlist[F("repeat")] = playlistRepeat; // TODO: this one is decreasing with each loop
69- playlist[F("end")] = playlistEndPreset;
70-
71- File f = WLED_FS.open("/playlist.json", "w");
72- if (f) serializeJson(doc, f);
73- f.close();
74- }
75- */
76-
7737void unloadPlaylist () {
7838 if (playlistEntries != nullptr ) {
7939 delete[] playlistEntries;
@@ -84,7 +44,6 @@ void unloadPlaylist() {
8444}
8545
8646void loadPlaylist (JsonObject playlistObj) {
87-
8847 unloadPlaylist ();
8948
9049 JsonArray presets = playlistObj[" ps" ];
@@ -147,9 +106,7 @@ void handlePlaylist() {
147106 ++playlistIndex %= playlistLen; // -1 at 1st run (limit to playlistLen)
148107
149108 if (!playlistRepeat && !playlistIndex) { // stop if repeat == 0 and restart of playlist
150- currentPlaylist = -1 ;
151- delete[] playlistEntries;
152- playlistEntries = nullptr ;
109+ unloadPlaylist ();
153110 if (playlistEndPreset) applyPreset (playlistEndPreset);
154111 return ;
155112 }
0 commit comments