audioPlayInit (including isWifiConnected)
This commit is contained in:
parent
3a19563278
commit
35c8ec13ee
@ -9,6 +9,7 @@
|
|||||||
#include <SD.h>
|
#include <SD.h>
|
||||||
|
|
||||||
#include "SnapClient.h"
|
#include "SnapClient.h"
|
||||||
|
#include "wifi.h"
|
||||||
|
|
||||||
AudioBoardStream board(AudioKitEs8388V1);
|
AudioBoardStream board(AudioKitEs8388V1);
|
||||||
|
|
||||||
@ -68,12 +69,36 @@ bool audioBeginMP3Stream(const char *code, Stream &source) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool audioPlayICY(const String &url) {
|
bool audioPlayInit(const char *code, const String &url, const bool needsWiFi, const bool needsSD) {
|
||||||
audioStop();
|
audioStop();
|
||||||
|
|
||||||
Serial.printf("[ICY] %s", url.c_str());
|
Serial.printf("[%s] %s", code, url.c_str());
|
||||||
running = true;
|
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())) {
|
if (!icy.begin(url.c_str())) {
|
||||||
Serial.println("[ICY] Failed to start ICYStream.");
|
Serial.println("[ICY] Failed to start ICYStream.");
|
||||||
audioStop();
|
audioStop();
|
||||||
@ -83,14 +108,13 @@ bool audioPlayICY(const String &url) {
|
|||||||
return audioBeginMP3Stream("ICY", icy);
|
return audioBeginMP3Stream("ICY", icy);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool audioPlaySNAP(const String &host) {
|
bool audioPlaySNAP(const String &url) {
|
||||||
audioStop();
|
if (!audioPlayInit("SNAP", url, true, false)) {
|
||||||
|
return false;
|
||||||
Serial.printf("[SNAP] %s\n", host.c_str());
|
}
|
||||||
running = true;
|
|
||||||
|
|
||||||
IPAddress ip;
|
IPAddress ip;
|
||||||
if (!WiFiClass::hostByName(host.c_str(), ip)) {
|
if (!WiFiClass::hostByName(url.c_str(), ip)) {
|
||||||
Serial.println("[SNAP] Failed to resolve host.");
|
Serial.println("[SNAP] Failed to resolve host.");
|
||||||
audioStop();
|
audioStop();
|
||||||
return false;
|
return false;
|
||||||
@ -119,14 +143,7 @@ bool audioPlaySNAP(const String &host) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool audioPlaySD(const String &url) {
|
bool audioPlaySD(const String &url) {
|
||||||
audioStop();
|
if (!audioPlayInit("SD", url, false, true)) {
|
||||||
|
|
||||||
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();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user