Directories working, web interface

This commit is contained in:
2023-06-04 23:15:11 +02:00
parent 2dd95a35eb
commit f173272f8b
4 changed files with 149 additions and 82 deletions

View File

@@ -116,31 +116,72 @@ DirectoryNode *DirectoryNode::findFirstDirectoryWithMP3s()
return nullptr;
}
void DirectoryNode::advanceToNextMP3()
void DirectoryNode::advanceToFirstMP3InThisNode() {
if (mp3Files.size()>0) {
currentPlaying = &mp3Files[0];
}
}
DirectoryNode* DirectoryNode::advanceToNextMP3(const String* currentGlobal)
{
if (currentPlaying != nullptr)
bool useFirst = false;
Serial.println(currentGlobal->c_str());
if (currentGlobal != nullptr)
{
for (size_t i = 0; i < mp3Files.size(); i++)
{
if (*currentPlaying == mp3Files[i])
if (*currentGlobal == mp3Files[i])
{
// Found the current playing MP3 file
if (i < mp3Files.size() - 1)
{
// Advance to the next MP3 file in the same directory
currentPlaying = &mp3Files[i + 1];
return;
return this;
}
useFirst = true;
// Reached the end of the MP3 files in the directory
break;
}
}
}
// We are either not playing, or we've exhausted all the MP3 files in this directory.
// Therefore, we need to recursively look in our subdirectories.
for (auto subdir : subdirectories)
{
Serial.println("searching next node");
if (useFirst && subdir->mp3Files.size()>0) {
subdir->currentPlaying = &subdir->mp3Files[0];
return subdir;
}
// Have each subdirectory advance its song
for (size_t i = 0; i < subdir->mp3Files.size(); i++)
{
if (*currentGlobal == subdir->mp3Files[i])
{
// Found the current playing MP3 file
if (i < subdir->mp3Files.size() - 1)
{
// Advance to the next MP3 file in the same directory
subdir->currentPlaying = &subdir->mp3Files[i + 1];
return subdir;
} else {
useFirst = true;
}
// Reached the end of the MP3 files in the directory
break;
}
}
}
// If not playing or reached the end, set the first MP3 file as the current playing
if (!mp3Files.empty())
{
currentPlaying = &mp3Files[0];
}
// If we get here, there were no MP3 files or subdirectories left to check
currentPlaying = nullptr;
Serial.println("no more nodes found");
return this;
}
String DirectoryNode::getDirectoryStructureHTML() const