mp3player
This commit is contained in:
parent
f173272f8b
commit
b6f72130a2
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef GLOBALS_H_
|
||||
#define GLOBALS_H_
|
||||
|
||||
void stop();
|
||||
|
||||
void start();
|
||||
|
||||
|
||||
#endif
|
||||
32
src/main.cpp
32
src/main.cpp
|
|
@ -16,9 +16,11 @@
|
|||
#include <SPI.h>
|
||||
#include <SD.h>
|
||||
|
||||
#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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue