audioPlayInit (including isWifiConnected)

This commit is contained in:
Patrick Haßel 2025-06-05 14:40:00 +02:00
parent 3a19563278
commit 35c8ec13ee

View File

@ -9,6 +9,7 @@
#include <SD.h>
#include "SnapClient.h"
#include "wifi.h"
AudioBoardStream board(AudioKitEs8388V1);
@ -68,12 +69,36 @@ bool audioBeginMP3Stream(const char *code, Stream &source) {
return true;
}
bool audioPlayICY(const String &url) {
bool audioPlayInit(const char *code, const String &url, const bool needsWiFi, const bool needsSD) {
audioStop();
Serial.printf("[ICY] %s", url.c_str());
Serial.printf("[%s] %s", code, url.c_str());
running = true;
if (needsWiFi) {
if (!isWifiConnected()) {
Serial.printf("[%s] WiFi not connected.\n", code);
audioStop();
return false;
}
}
if (needsSD) {
if (!SD.begin(PIN_AUDIO_KIT_SD_CARD_CS)) {
Serial.printf("[%s] Failed to mount SD-card.\n", code);
audioStop();
return false;
}
}
return true;
}
bool audioPlayICY(const String &url) {
if (!audioPlayInit("ICY", url, true, false)) {
return false;
}
if (!icy.begin(url.c_str())) {
Serial.println("[ICY] Failed to start ICYStream.");
audioStop();
@ -83,14 +108,13 @@ bool audioPlayICY(const String &url) {
return audioBeginMP3Stream("ICY", icy);
}
bool audioPlaySNAP(const String &host) {
audioStop();
Serial.printf("[SNAP] %s\n", host.c_str());
running = true;
bool audioPlaySNAP(const String &url) {
if (!audioPlayInit("SNAP", url, true, false)) {
return false;
}
IPAddress ip;
if (!WiFiClass::hostByName(host.c_str(), ip)) {
if (!WiFiClass::hostByName(url.c_str(), ip)) {
Serial.println("[SNAP] Failed to resolve host.");
audioStop();
return false;
@ -119,14 +143,7 @@ bool audioPlaySNAP(const String &host) {
}
bool audioPlaySD(const String &url) {
audioStop();
Serial.printf("[SD] %s\n", url.c_str());
running = true;
if (!SD.begin(PIN_AUDIO_KIT_SD_CARD_CS)) {
Serial.println("[SD] Failed to mount SD-card.");
audioStop();
if (!audioPlayInit("SD", url, false, true)) {
return false;
}