Compare commits

..

No commits in common. "63eb980c323dba1daf77bec39b917d1e795440cb" and "fbb800c47279986d0a3f1c46e1e49dea4a8b15ee" have entirely different histories.

4 changed files with 19 additions and 51 deletions

View File

@ -36,7 +36,7 @@ MP3DecoderHelix mp3Decoder;
EncodedAudioStream mp3Stream(&board, &mp3Decoder);
StreamCopy mp3Copier;
StreamCopy copier;
bool running = false;
@ -46,7 +46,7 @@ void audioStop() {
Serial.println("[AUDIO ] STOP");
}
copyErrors = 0;
mp3Copier.end();
copier.end();
mp3Stream.end();
mp3Decoder.end();
opusDecoder.end();
@ -58,12 +58,12 @@ void audioStop() {
bool audioPlayInit(const Entry &entry) {
audioStop();
Serial.printf("[AUDIO ] [%s] Opening: %s\n", entry.type.c_str(), entry.url.c_str());
Serial.printf("[AUDIO ] [%-4s] Start: %s\n", entry.type.c_str(), entry.url.c_str());
running = true;
if (entry.type == "ICY" || entry.type == "SNAP") {
if (!isWifiConnected()) {
Serial.printf("[AUDIO ] [%s] WiFi not connected.\n", entry.type.c_str());
Serial.printf("[AUDIO ] [%-4s] WiFi not connected.\n", entry.type.c_str());
audioStop();
return false;
}
@ -71,7 +71,7 @@ bool audioPlayInit(const Entry &entry) {
if (entry.type == "SD") {
if (!SD.begin(PIN_AUDIO_KIT_SD_CARD_CS)) {
Serial.printf("[AUDIO ] [%s] Failed to mount SD-card.\n", entry.type.c_str());
Serial.printf("[AUDIO ] [%-4s] Failed to mount SD-card.\n", entry.type.c_str());
audioStop();
return false;
}
@ -82,26 +82,25 @@ bool audioPlayInit(const Entry &entry) {
bool audioBeginMP3Stream(const Entry &entry, Stream &source) {
if (!mp3Decoder.begin()) {
Serial.printf("[AUDIO ] [%s] Failed to start MP3DecoderHelix.", entry.type.c_str());
Serial.printf("[AUDIO ] [%-4s] Failed to start MP3DecoderHelix.", entry.type.c_str());
audioStop();
return false;
}
if (!mp3Stream.begin()) {
Serial.printf("[AUDIO ] [%s] Failed to start EncodedAudioStream.", entry.type.c_str());
Serial.printf("[AUDIO ] [%-4s] Failed to start EncodedAudioStream.", entry.type.c_str());
audioStop();
return false;
}
mp3Copier.begin(mp3Stream, source);
copier.begin(mp3Stream, source);
if (mp3Copier.copy() == 0) {
Serial.printf("[AUDIO ] [%s] Failed to copy initial data.", entry.type.c_str());
if (copier.copy() == 0) {
Serial.printf("[AUDIO ] [%-4s] Failed to copy initial data.", entry.type.c_str());
audioStop();
return false;
}
Serial.printf("[AUDIO ] [%s] Stream running.\n", entry.type.c_str());
return true;
}
@ -111,7 +110,7 @@ bool audioPlayICY(const Entry &entry) {
}
if (!icy.begin(entry.url.c_str())) {
Serial.printf("[AUDIO ] [%s] Failed to start ICYStream.\n", entry.type.c_str());
Serial.printf("[AUDIO ] [%-4s] Failed to start ICYStream.\n", entry.type.c_str());
audioStop();
return false;
}
@ -126,31 +125,30 @@ bool audioPlaySNAP(const Entry &entry) {
IPAddress ip;
if (!WiFiClass::hostByName(entry.url.c_str(), ip)) {
Serial.printf("[AUDIO ] [%s] Failed to resolve host.\n", entry.type.c_str());
Serial.printf("[AUDIO ] [%-4s] Failed to resolve host.\n", entry.type.c_str());
audioStop();
return false;
}
snap.setServerIP(ip);
if (!snap.begin()) {
Serial.printf("[AUDIO ] [%s] Failed to connect.\n", entry.type.c_str());
Serial.printf("[AUDIO ] [%-4s] Failed to connect.\n", entry.type.c_str());
audioStop();
return false;
}
if (!opusDecoder.begin()) {
Serial.printf("[AUDIO ] [%s] Failed to start OpusAudioDecoder.\n", entry.type.c_str());
Serial.printf("[AUDIO ] [%-4s] Failed to start OpusAudioDecoder.\n", entry.type.c_str());
audioStop();
return false;
}
if (!snap.doLoop()) {
Serial.printf("[AUDIO ] [%s] Failed to copy initial data.\n", entry.type.c_str());
Serial.printf("[AUDIO ] [%-4s] Failed to copy initial data.\n", entry.type.c_str());
audioStop();
return false;
}
Serial.printf("[AUDIO ] [%s] Stream running.\n", entry.type.c_str());
return true;
}
@ -160,14 +158,14 @@ bool audioPlaySD(const Entry &entry) {
}
if (!SD.exists(entry.url.c_str())) {
Serial.printf("[AUDIO ] [%s] File not found.\n", entry.type.c_str());
Serial.printf("[AUDIO ] [%-4s] File not found.\n", entry.type.c_str());
audioStop();
return false;
}
file = SD.open(entry.url.c_str(), FILE_READ);
if (!file) {
Serial.printf("[AUDIO ] [%s] Failed to open file.\n", entry.type.c_str());
Serial.printf("[AUDIO ] [%-4s] Failed to open file.\n", entry.type.c_str());
audioStop();
return false;
}
@ -212,15 +210,12 @@ bool audioLoop() {
board.setMute(audioMute);
stateBufferUpdateRequest();
}
// TODO check snap too
if (mp3Copier.copy() > 0 || mp3Stream.availableForWrite() > 0) {
if (copier.copy() > 0) {
copyErrors = 0;
return true;
}
if (running) {
copyErrors = 100;
copyErrors++;
if (copyErrors < 100) {
return true;
}

View File

@ -79,24 +79,6 @@ void httpSetup() {
playerSkip -= 1;
request->send(200);
});
server.on("/repeatOne", [](AsyncWebServerRequest *request) {
Serial.println("[HTTP ] " + request->url());
playlistRepeatOne = !playlistRepeatOne;
stateBufferUpdateRequest();
request->send(200);
});
server.on("/repeatAll", [](AsyncWebServerRequest *request) {
Serial.println("[HTTP ] " + request->url());
playlistRepeatAll = !playlistRepeatAll;
stateBufferUpdateRequest();
request->send(200);
});
server.on("/random", [](AsyncWebServerRequest *request) {
Serial.println("[HTTP ] " + request->url());
playlistRandom = !playlistRandom;
stateBufferUpdateRequest();
request->send(200);
});
ws.onEvent(onWebSocketEvent);
server.addHandler(&ws);
server.begin();

View File

@ -105,9 +105,6 @@ Entry playlistCurrent() {
}
Entry playlistNext(const int amount) {
if (playlistRandom) {
return playlistSet(random(static_cast<long>(playlistEntries.size())));
}
if (amount < 0 && playlistIndex <= 0 && !playlistRepeatAll) {
return Entry();
}

View File

@ -3,12 +3,6 @@
#include "Entry.h"
extern bool playlistRepeatOne;
extern bool playlistRepeatAll;
extern bool playlistRandom;
void playlistClear();
void playlistAdd(String entry);