[ai] Resume to progress in s fixed

This commit is contained in:
Stefan Ostermann 2025-08-17 22:07:59 +02:00
parent b8e1263fb3
commit 72781503fa
2 changed files with 33 additions and 26 deletions

View File

@ -391,9 +391,7 @@ void playSongById(uint16_t id, uint32_t continueSeconds = 0)
}
Serial.print("Playing by ID: ");
Serial.print(id);
Serial.print(" ");
Serial.println(continueSeconds);
Serial.println(id);
Serial.println(mp3File.c_str());
deactivateRFID();
@ -405,10 +403,10 @@ void playSongById(uint16_t id, uint32_t continueSeconds = 0)
currentNode = nullptr;
return;
}
if (continueSeconds != 0)
if (continueSeconds > 0)
{
audio.setAudioPlayPosition(continueSeconds);
pendingSeekSeconds = continueSeconds;
pendingSeek = true;
}
}
@ -561,7 +559,6 @@ void playSongByRFID(String id)
return;
}
}
/**
@ -612,7 +609,8 @@ void playNextMp3()
Serial.print("Advancing to ");
String mp3File = currentNode->getCurrentPlayingFilePath();
// FIXME crash here if last song.
if (mp3File.isEmpty()) {
if (mp3File.isEmpty())
{
currentNode = rootNode.findFirstDirectoryWithMP3s();
return;
@ -739,7 +737,6 @@ String getState()
output.reserve(512); // Pre-allocate string buffer
output.clear();
jsonState.clear(); // Clear previous data
jsonState["playing"] = audio.isRunning();
@ -761,7 +758,6 @@ String getState()
jsonState["uid"] = lastUid;
jsonState["heap"] = free_heap;
serializeJson(jsonState, output);
return output;
@ -1265,8 +1261,7 @@ void setup()
// Fallback: serve minimal error if file not found
request->send(404, "text/plain", "ERROR: /system/index.html not found!");
}
webrequestActive = false;
});
webrequestActive = false; });
server.on("/style.css", HTTP_GET, [](AsyncWebServerRequest *request)
{
@ -1284,8 +1279,7 @@ void setup()
// Fallback: serve minimal CSS if file not found
request->send(404, "text/plain", "ERROR: /system/style.css not found!");
}
webrequestActive = false;
});
webrequestActive = false; });
server.on("/script.js", HTTP_GET, [](AsyncWebServerRequest *request)
{
@ -1302,8 +1296,7 @@ void setup()
// Fallback: serve minimal JS if file not found
request->send(404, "text/plain", "ERROR: /system/script.js not found!");
}
webrequestActive = false;
});
webrequestActive = false; });
server.on("/state", HTTP_GET, [](AsyncWebServerRequest *request)
{
@ -1451,6 +1444,16 @@ void loop()
{
currentNode->setSecondsPlayed(audio.getAudioCurrentTime());
}
// Apply pending seek once decoder is ready (after header parsed and bitrate known)
if (pendingSeek && audio.getBitRate(true) > 0 && audio.getAudioFileDuration() > 0)
{
audio.setAudioPlayPosition(pendingSeekSeconds);
if (currentNode != nullptr)
{
currentNode->setSecondsPlayed(pendingSeekSeconds);
}
pendingSeek = false;
}
}
else if (asyncStart)
{
@ -1463,6 +1466,7 @@ void loop()
continuePlaying = false;
startupSoundPlayed = true;
playSongById(currentSongId, currentSongSeconds);
currentNode->setSecondsPlayed(currentSongSeconds);
}
else if (!startupSoundPlayed)
{

View File

@ -99,4 +99,7 @@ std::map<String, MappingEntry> rfid_map;
// track of the folder root node so EOF handling can advance only inside that folder.
bool folderModeActive = false;
bool pendingSeek = false;
uint32_t pendingSeekSeconds = 0;
#endif