fixed some crashes, html..
This commit is contained in:
@@ -119,7 +119,10 @@ void DirectoryNode::buildDirectoryTree(const char *currentPath)
|
||||
}
|
||||
else if (String(entry.name()).endsWith(".mp3")||String(entry.name()).endsWith(".MP3"))
|
||||
{
|
||||
mp3Files.push_back(entry.name());
|
||||
String fullPath = String(currentPath);
|
||||
if (!fullPath.endsWith("/")) fullPath += "/";
|
||||
fullPath += entry.name();
|
||||
mp3Files.push_back(fullPath);
|
||||
ids.push_back(getNextId());
|
||||
}
|
||||
entry.close();
|
||||
@@ -182,75 +185,97 @@ void DirectoryNode::advanceToFirstMP3InThisNode()
|
||||
|
||||
DirectoryNode *DirectoryNode::advanceToMP3(const uint16_t id)
|
||||
{
|
||||
|
||||
|
||||
// First check MP3 files in this directory
|
||||
for (size_t i = 0; i < ids.size(); i++)
|
||||
{
|
||||
if (id == ids[i])
|
||||
{
|
||||
if (id == ids[i])
|
||||
{
|
||||
// Found the current MP3 file
|
||||
currentPlaying = &mp3Files[i];
|
||||
currentPlayingId = id;
|
||||
return this;
|
||||
}
|
||||
// Found the current MP3 file
|
||||
currentPlaying = &mp3Files[i];
|
||||
currentPlayingId = id;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
// Recursively search subdirectories
|
||||
for (auto subdir : subdirectories)
|
||||
{
|
||||
// Check if the ID matches a subdirectory ID
|
||||
if (subdir->getId() == id)
|
||||
{
|
||||
subdir->advanceToFirstMP3InThisNode();
|
||||
return subdir;
|
||||
}
|
||||
|
||||
// Have each subdirectory advance its song
|
||||
for (size_t i = 0; i < subdir->ids.size(); i++)
|
||||
// Recursively search in subdirectory
|
||||
DirectoryNode* result = subdir->advanceToMP3(id);
|
||||
if (result != nullptr && result->getCurrentPlaying() != nullptr)
|
||||
{
|
||||
if (id == subdir->ids[i])
|
||||
{
|
||||
// Found the current MP3 file
|
||||
subdir->currentPlaying = &subdir->mp3Files[i];
|
||||
subdir->currentPlayingId = id;
|
||||
return subdir;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// If we get here, there were no MP3 files or subdirectories left to check
|
||||
currentPlaying = nullptr;
|
||||
Serial.println("no more nodes found");
|
||||
return this;
|
||||
// If we get here, no song with this ID was found
|
||||
Serial.println("advanceToMP3: No song found for ID: " + String(id));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DirectoryNode *DirectoryNode::advanceToMP3(const String *currentGlobal)
|
||||
{
|
||||
if (currentGlobal == nullptr) {
|
||||
Serial.println("advanceToMP3: currentGlobal is null");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Check if the input is an absolute path (starts with '/') or just a filename
|
||||
bool isAbsolutePath = currentGlobal->startsWith("/");
|
||||
|
||||
// First, check MP3 files in this directory
|
||||
for (size_t i = 0; i < mp3Files.size(); i++)
|
||||
{
|
||||
if (isAbsolutePath) {
|
||||
// For absolute paths, do exact match
|
||||
if (*currentGlobal == mp3Files[i])
|
||||
{
|
||||
setCurrentPlaying(&mp3Files[i]);
|
||||
return this;
|
||||
}
|
||||
} else {
|
||||
// For filenames, extract filename from full path and compare
|
||||
String filename = mp3Files[i];
|
||||
int lastSlash = filename.lastIndexOf('/');
|
||||
if (lastSlash != -1) {
|
||||
filename = filename.substring(lastSlash + 1);
|
||||
}
|
||||
if (*currentGlobal == filename)
|
||||
{
|
||||
setCurrentPlaying(&mp3Files[i]);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Recursively search subdirectories
|
||||
for (auto subdir : subdirectories)
|
||||
{
|
||||
if (subdir->getName() == *currentGlobal)
|
||||
// Check if the string matches a directory name (only for non-absolute paths)
|
||||
if (!isAbsolutePath && subdir->getName() == *currentGlobal)
|
||||
{
|
||||
subdir->advanceToFirstMP3InThisNode();
|
||||
return subdir;
|
||||
}
|
||||
|
||||
// Have each subdirectory advance its song
|
||||
for (size_t i = 0; i < subdir->mp3Files.size(); i++)
|
||||
// Recursively search in subdirectory
|
||||
DirectoryNode* result = subdir->advanceToMP3(currentGlobal);
|
||||
if (result != nullptr && result->getCurrentPlaying() != nullptr)
|
||||
{
|
||||
if (*currentGlobal == subdir->mp3Files[i])
|
||||
{
|
||||
// Found the current MP3 file
|
||||
if (i < subdir->mp3Files.size() - 1)
|
||||
{
|
||||
subdir->setCurrentPlaying(&subdir->mp3Files[i]);
|
||||
return subdir;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// If we get here, there were no MP3 files or subdirectories left to check
|
||||
currentPlaying = nullptr;
|
||||
Serial.println("no more nodes found");
|
||||
return this;
|
||||
// If we get here, no matching song was found
|
||||
Serial.println("advanceToMP3: No song found for: " + *currentGlobal);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -466,16 +491,7 @@ String DirectoryNode::getCurrentPlayingFilePath() const
|
||||
{
|
||||
if (currentPlaying != nullptr)
|
||||
{
|
||||
String filePath = name;
|
||||
if (!filePath.startsWith("/")) {
|
||||
filePath = "/"+filePath;
|
||||
}
|
||||
if (!filePath.endsWith("/"))
|
||||
{
|
||||
filePath += "/";
|
||||
}
|
||||
filePath += *currentPlaying;
|
||||
return filePath;
|
||||
return *currentPlaying;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user