[ai] Resume to progress in s fixed
This commit is contained in:
parent
b8e1263fb3
commit
72781503fa
56
src/main.cpp
56
src/main.cpp
|
|
@ -58,14 +58,14 @@ Audio audio;
|
|||
|
||||
uint volume = 7;
|
||||
|
||||
// Folder-play tracking: flattened list of files inside a mapped folder and current index
|
||||
// Used when a mapping targets a folder (play folder once or loop folder)
|
||||
#include <vector>
|
||||
static std::vector<std::pair<DirectoryNode*, int>> folderFlatList;
|
||||
static int folderFlatIndex = -1;
|
||||
static String folderRootPath = "";
|
||||
// Pointer to the root DirectoryNode for active folder-mode playback
|
||||
DirectoryNode* folderRootNode = nullptr;
|
||||
// Folder-play tracking: flattened list of files inside a mapped folder and current index
|
||||
// Used when a mapping targets a folder (play folder once or loop folder)
|
||||
#include <vector>
|
||||
static std::vector<std::pair<DirectoryNode *, int>> folderFlatList;
|
||||
static int folderFlatIndex = -1;
|
||||
static String folderRootPath = "";
|
||||
// Pointer to the root DirectoryNode for active folder-mode playback
|
||||
DirectoryNode *folderRootNode = nullptr;
|
||||
|
||||
AsyncWebServer server(80);
|
||||
DNSServer dns;
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -611,9 +608,10 @@ void playNextMp3()
|
|||
|
||||
Serial.print("Advancing to ");
|
||||
String mp3File = currentNode->getCurrentPlayingFilePath();
|
||||
//FIXME crash here if last song.
|
||||
if (mp3File.isEmpty()) {
|
||||
|
||||
// FIXME crash here if last song.
|
||||
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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue