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
|
||||||
28
src/main.cpp
28
src/main.cpp
|
|
@ -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:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue