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 <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: