Player: runtime source override and play-a-URL on /api/player
The player now owns the effective mode (config or override) and passes it down: spotify_apply(enable) and hls_set_url(url) instead of both reading source.mode from the config. /api/player/source forces spotify|hls|off (config returns to the saved mode), /api/player/url plays an m3u8 now; neither is saved. GET reports it in `forced`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -33,6 +33,7 @@ static std::shared_ptr<cspot::LoginBlob> s_blob; // guarded by s_mutex
|
||||
static std::mutex s_mutex;
|
||||
static std::string s_name; // advertised device name ("" = not advertised)
|
||||
static std::atomic<bool> s_enabled{false};
|
||||
static std::atomic<bool> s_want{false}; // last spotify_apply(): the player needs Spotify
|
||||
static std::atomic<bool> s_stop{false}; // end the running session
|
||||
static std::atomic<bool> s_got_blob{false};
|
||||
static std::atomic<bool> s_in_session{false}; // session() running (its tasks may exist)
|
||||
@@ -107,7 +108,7 @@ static void check_playback(const std::shared_ptr<cspot::SpircHandler> &handler)
|
||||
extern "C" void spotify_suspend(bool suspend)
|
||||
{
|
||||
if (!suspend) {
|
||||
spotify_apply();
|
||||
spotify_apply(s_want);
|
||||
return;
|
||||
}
|
||||
s_enabled = false;
|
||||
@@ -500,15 +501,15 @@ static void spotify_task(void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void spotify_apply(void)
|
||||
extern "C" void spotify_apply(bool enable)
|
||||
{
|
||||
s_want = enable;
|
||||
cJSON *src = cfg_get("source");
|
||||
std::string mode = cJSON_GetObjectItemCaseSensitive(src, "mode")->valuestring;
|
||||
std::string name = cJSON_GetObjectItemCaseSensitive(src, "spotify_name")->valuestring;
|
||||
bool creds = cJSON_GetObjectItemCaseSensitive(src, "spotify_client_id")->valuestring[0] &&
|
||||
cJSON_GetObjectItemCaseSensitive(src, "spotify_client_secret")->valuestring[0];
|
||||
cJSON_Delete(src);
|
||||
bool want = (mode == "spotify" || mode == "auto") && creds;
|
||||
bool want = enable && creds;
|
||||
|
||||
if (!want || name != s_name) {
|
||||
// Disable, or re-advertise under a new name: end any session, drop the old entry.
|
||||
@@ -523,7 +524,7 @@ extern "C" void spotify_apply(void)
|
||||
}
|
||||
if (!want) {
|
||||
s_state = !creds ? "no client credentials" : "disabled (source mode)";
|
||||
if (!creds && (mode == "spotify" || mode == "auto")) {
|
||||
if (!creds && enable) {
|
||||
ESP_LOGW(TAG, "not started: set the Spotify client ID and secret (web UI, Source)");
|
||||
}
|
||||
return;
|
||||
@@ -558,6 +559,5 @@ extern "C" esp_err_t spotify_init(spotify_pcm_cb_t pcm, spotify_event_cb_t event
|
||||
if (xTaskCreate(spotify_task, "spotify", 32 * 1024, nullptr, 5, nullptr) != pdPASS) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
spotify_apply();
|
||||
return ESP_OK;
|
||||
return ESP_OK; // the player enables it (spotify_apply)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user