- reduce playlist repetition count on save #3058
This commit is contained in:
Blaz Kristan 2023-01-29 11:27:14 +01:00
parent b91b340afd
commit ca73a57de7
2 changed files with 4 additions and 3 deletions

View File

@ -156,7 +156,7 @@ void serializePlaylist(JsonObject sObj) {
JsonArray ps = playlist.createNestedArray("ps"); JsonArray ps = playlist.createNestedArray("ps");
JsonArray dur = playlist.createNestedArray("dur"); JsonArray dur = playlist.createNestedArray("dur");
JsonArray transition = playlist.createNestedArray(F("transition")); JsonArray transition = playlist.createNestedArray(F("transition"));
playlist[F("repeat")] = playlistRepeat; playlist[F("repeat")] = (playlistRepeat > 0) ? playlistRepeat - 1 : 0; // remove added repetition count
playlist["end"] = playlistEndPreset; playlist["end"] = playlistEndPreset;
playlist["r"] = playlistOptions & PL_OPTION_SHUFFLE; playlist["r"] = playlistOptions & PL_OPTION_SHUFFLE;
for (int i=0; i<playlistLen; i++) { for (int i=0; i<playlistLen; i++) {

View File

@ -210,7 +210,7 @@ void savePreset(byte index, const char* pname, JsonObject sObj)
} else { } else {
// this is a playlist or API call // this is a playlist or API call
if (sObj[F("playlist")].isNull()) { if (sObj[F("playlist")].isNull()) {
// we will save API call immediately // we will save API call immediately (often causes presets.json corruption)
presetToSave = 0; presetToSave = 0;
if (index > 250 || !fileDoc) return; // cannot save API calls to temporary preset (255) if (index > 250 || !fileDoc) return; // cannot save API calls to temporary preset (255)
sObj.remove("o"); sObj.remove("o");
@ -220,11 +220,12 @@ void savePreset(byte index, const char* pname, JsonObject sObj)
sObj.remove(F("psave")); sObj.remove(F("psave"));
if (sObj["n"].isNull()) sObj["n"] = saveName; if (sObj["n"].isNull()) sObj["n"] = saveName;
initPresetsFile(); // just in case if someone deleted presets.json using /edit initPresetsFile(); // just in case if someone deleted presets.json using /edit
writeObjectToFileUsingId(getFileName(index), index, fileDoc); writeObjectToFileUsingId(getFileName(index<255), index, fileDoc);
presetsModifiedTime = toki.second(); //unix time presetsModifiedTime = toki.second(); //unix time
updateFSInfo(); updateFSInfo();
} else { } else {
// store playlist // store playlist
// WARNING: playlist will be loaded in json.cpp after this call and will have repeat counter increased by 1
includeBri = true; // !sObj["on"].isNull(); includeBri = true; // !sObj["on"].isNull();
playlistSave = true; playlistSave = true;
} }