Skip to content

Wait when trying to play a webstream while connecting to wifi #284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/AudioPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,9 +751,18 @@ void AudioPlayer_Task(void *parameter) {
audioReturnCode = false;

if (gPlayProperties.playMode == WEBSTREAM || (gPlayProperties.playMode == LOCAL_M3U && gPlayProperties.isWebstream)) { // Webstream
audioReturnCode = audio->connecttohost(gPlayProperties.playlist->at(gPlayProperties.currentTrackNumber));
gPlayProperties.playlistFinished = false;
gTriedToConnectToHost = true;
// wait for wlan to connect or fail to connect before continuing
// NOTE: In the current implementation, the Wifi only tries to connect for a few seconds. So this should not block too long.
while (Wlan_ConnectionTryInProgress()) {
vTaskDelay(portTICK_PERIOD_MS * 100u);
}
if (!Wlan_IsConnected()) {
Log_Println(webstreamNotAvailable, LOGLEVEL_ERROR);
audioReturnCode = false;
} else {
audioReturnCode = audio->connecttohost(gPlayProperties.playlist->at(gPlayProperties.currentTrackNumber));
gPlayProperties.playlistFinished = false;
}
} else if (gPlayProperties.playMode != WEBSTREAM && !gPlayProperties.isWebstream) {
// Files from SD
if (!gFSystem.exists(gPlayProperties.playlist->at(gPlayProperties.currentTrackNumber))) { // Check first if file/folder exists
Expand Down Expand Up @@ -1140,10 +1149,6 @@ void AudioPlayer_TrackQueueDispatcher(const char *_itemToPlay, const uint32_t _l

case WEBSTREAM: { // This is always just one "track"
Log_Println(modeWebstream, LOGLEVEL_NOTICE);
if (!Wlan_IsConnected()) {
Log_Println(webstreamNotAvailable, LOGLEVEL_ERROR);
error = true;
}
break;
}

Expand Down
14 changes: 1 addition & 13 deletions src/Wlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,18 +496,6 @@ void handleWifiStateConnectionSuccess() {
delete dnsServer;
dnsServer = nullptr;

bool playLastRfidAfterReboot;
#ifdef PLAY_LAST_RFID_AFTER_REBOOT
playLastRfidAfterReboot = gPrefsSettings.getBool("playLastOnBoot", true);
#else
playLastRfidAfterReboot = gPrefsSettings.getBool("playLastOnBoot", false);
#endif

if (playLastRfidAfterReboot && gPlayLastRfIdWhenWiFiConnected && gTriedToConnectToHost) {
gPlayLastRfIdWhenWiFiConnected = false;
recoverLastRfidPlayedFromNvs(true);
}

wifiState = WIFI_STATE_CONNECTED;
Mqtt_OnWifiConnected();
}
Expand Down Expand Up @@ -720,7 +708,7 @@ bool Wlan_DeleteNetwork(String ssid) {
}

bool Wlan_ConnectionTryInProgress(void) {
return wifiState == WIFI_STATE_SCAN_CONN;
return wifiState == WIFI_STATE_INIT || wifiState == WIFI_STATE_CONNECT_LAST || wifiState == WIFI_STATE_SCAN_CONN;
}

String Wlan_GetIpAddress(void) {
Expand Down
8 changes: 2 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@

#include <Wire.h>

bool gPlayLastRfIdWhenWiFiConnected = false;
bool gTriedToConnectToHost = false;

static constexpr const char *logo = R"literal(
_____ ____ ____ _
| ____| / ___| | _ \ _ _ (_) _ __ ___
Expand Down Expand Up @@ -94,8 +91,8 @@ void recoverBootCountFromNvs(void) {
}

// Get last RFID-tag applied from NVS
void recoverLastRfidPlayedFromNvs(bool force) {
if (recoverLastRfid || force) {
void recoverLastRfidPlayedFromNvs() {
if (recoverLastRfid) {
if (System_GetOperationMode() == OPMODE_BLUETOOTH_SINK) { // Don't recover if BT-mode is desired
recoverLastRfid = false;
return;
Expand All @@ -106,7 +103,6 @@ void recoverLastRfidPlayedFromNvs(bool force) {
Log_Println(unableToRestoreLastRfidFromNVS, LOGLEVEL_INFO);
} else {
xQueueSend(gRfidCardQueue, lastRfidPlayed.c_str(), 0);
gPlayLastRfIdWhenWiFiConnected = !force;
Log_Printf(LOGLEVEL_INFO, restoredLastRfidFromNVS, lastRfidPlayed.c_str());
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/main.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#pragma once

extern bool gPlayLastRfIdWhenWiFiConnected;
extern bool gTriedToConnectToHost;

extern void recoverLastRfidPlayedFromNvs(bool force = false);
extern void recoverLastRfidPlayedFromNvs();
3 changes: 2 additions & 1 deletion src/revision.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once

#include "gitrevision.h"
constexpr const char softwareRevision[] = "Software-revision: 20250515-1-DEV";

constexpr const char softwareRevision[] = "Software-revision: 20250613-1-DEV";
Loading