diff --git a/src/globals.h b/src/globals.h new file mode 100644 index 0000000..19ed836 --- /dev/null +++ b/src/globals.h @@ -0,0 +1,9 @@ +#ifndef GLOBALS_H_ +#define GLOBALS_H_ + +void stop(); + +void start(); + + +#endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 5ee3bcb..95b0e07 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,9 +16,11 @@ #include #include +#include "globals.h" #include "WebContent.h" #include "DirectoryNode.h" + File root; File mp3File; @@ -34,12 +36,13 @@ DNSServer dns; DirectoryNode rootNode("/"); DirectoryNode *currentNode = NULL; -void stop(); +boolean blockState = false; + -void start(); void playNextMp3() { + blockState = true; stop(); if (currentNode == NULL) { @@ -58,6 +61,7 @@ void playNextMp3() Serial.println(mp3File.c_str()); audio.connecttoSD(mp3File.c_str()); + blockState = false; } void audio_info(const char *info) @@ -68,9 +72,20 @@ void audio_info(const char *info) String getState() { String state = String(); + + if (blockState) { + return state; + } + blockState = true; + if (audio.isRunning()) { state += "Playing "; + state += audio.getAudioCurrentTime(); + state += " / "; + state += audio.getAudioFileDuration(); + state += " "; + } else { @@ -83,6 +98,7 @@ String getState() if (currentNode->getCurrentPlaying()) state += *currentNode->getCurrentPlaying(); } + blockState = false; return state; } @@ -108,8 +124,11 @@ void stop() void start() { - currentNode->setCurrentPlaying(NULL); - currentNode = NULL; + if (currentNode!=NULL) { + currentNode->setCurrentPlaying(NULL); + currentNode = NULL; + } + playNextMp3(); } @@ -118,6 +137,11 @@ void next() playNextMp3(); } +void audio_eof_mp3(const char *info) { + Serial.println("audio file ended."); + playNextMp3(); +} + void setup() { // put your setup code here, to run once: