mp3player

This commit is contained in:
Stefan Ostermann 2023-06-05 12:35:31 +02:00
parent f173272f8b
commit b6f72130a2
2 changed files with 37 additions and 4 deletions

9
src/globals.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef GLOBALS_H_
#define GLOBALS_H_
void stop();
void start();
#endif

View File

@ -16,9 +16,11 @@
#include <SPI.h> #include <SPI.h>
#include <SD.h> #include <SD.h>
#include "globals.h"
#include "WebContent.h" #include "WebContent.h"
#include "DirectoryNode.h" #include "DirectoryNode.h"
File root; File root;
File mp3File; File mp3File;
@ -34,12 +36,13 @@ DNSServer dns;
DirectoryNode rootNode("/"); DirectoryNode rootNode("/");
DirectoryNode *currentNode = NULL; DirectoryNode *currentNode = NULL;
void stop(); boolean blockState = false;
void start();
void playNextMp3() void playNextMp3()
{ {
blockState = true;
stop(); stop();
if (currentNode == NULL) if (currentNode == NULL)
{ {
@ -58,6 +61,7 @@ void playNextMp3()
Serial.println(mp3File.c_str()); Serial.println(mp3File.c_str());
audio.connecttoSD(mp3File.c_str()); audio.connecttoSD(mp3File.c_str());
blockState = false;
} }
void audio_info(const char *info) void audio_info(const char *info)
@ -68,9 +72,20 @@ void audio_info(const char *info)
String getState() String getState()
{ {
String state = String(); String state = String();
if (blockState) {
return state;
}
blockState = true;
if (audio.isRunning()) if (audio.isRunning())
{ {
state += "Playing "; state += "Playing ";
state += audio.getAudioCurrentTime();
state += " / ";
state += audio.getAudioFileDuration();
state += " ";
} }
else else
{ {
@ -83,6 +98,7 @@ String getState()
if (currentNode->getCurrentPlaying()) if (currentNode->getCurrentPlaying())
state += *currentNode->getCurrentPlaying(); state += *currentNode->getCurrentPlaying();
} }
blockState = false;
return state; return state;
} }
@ -108,8 +124,11 @@ void stop()
void start() void start()
{ {
if (currentNode!=NULL) {
currentNode->setCurrentPlaying(NULL); currentNode->setCurrentPlaying(NULL);
currentNode = NULL; currentNode = NULL;
}
playNextMp3(); playNextMp3();
} }
@ -118,6 +137,11 @@ void next()
playNextMp3(); playNextMp3();
} }
void audio_eof_mp3(const char *info) {
Serial.println("audio file ended.");
playNextMp3();
}
void setup() void setup()
{ {
// put your setup code here, to run once: // put your setup code here, to run once: