Files
aes67-ESP32-P4/components/spotify/include/spotify.h
T
bsncubed e5c3c0ad8a 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>
2026-09-25 23:15:38 +10:00

65 lines
2.8 KiB
C

// Spotify Connect (cspot). Project code; GPL-3.0 through cspot.
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "esp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
SPOTIFY_EV_PLAY, // playback (re)started or resumed
SPOTIFY_EV_PAUSE,
SPOTIFY_EV_FLUSH, // skip, seek, new track: drop buffered audio
SPOTIFY_EV_VOLUME, // value: 0..65535
} spotify_event_t;
// PCM from Spotify: 44.1 kHz stereo s16 interleaved. Return the frames taken (may block).
typedef size_t (*spotify_pcm_cb_t)(const int16_t *pcm, size_t frames);
typedef void (*spotify_event_cb_t)(spotify_event_t ev, int value);
// Output positions in frames (monotonic, wrap at 2^32): written into the output buffer so far, and
// played out so far. Used to tell Spotify when a new track actually becomes audible.
typedef uint32_t (*spotify_pos_cb_t)(void);
// Registers the zeroconf endpoints (/spotify_info) and starts the session task (disabled until
// spotify_apply(true)).
esp_err_t spotify_init(spotify_pcm_cb_t pcm, spotify_event_cb_t event, spotify_pos_cb_t written,
spotify_pos_cb_t played);
// Enable (advertised, sessions accepted) when the player's mode needs Spotify and the client
// credentials are set; otherwise not advertised and a running session is ended. Re-reads name and
// credentials from the "source" config: a new device name ends the session and re-advertises.
void spotify_apply(bool enable);
typedef enum {
SPOTIFY_CMD_PLAY, SPOTIFY_CMD_PAUSE, SPOTIFY_CMD_NEXT, SPOTIFY_CMD_PREV,
SPOTIFY_CMD_SEEK, // arg: position in ms
} spotify_cmd_t;
// Control the running session (the Spotify app follows). Runs on the session task; waits until it
// has run (max 1 s). Returns false without a session.
bool spotify_command(spotify_cmd_t cmd, uint32_t arg);
// Suspend: end any running session (waits until its tasks are gone, max ~3 s) and refuse new ones.
// Resume: back to what the config says. Used around firmware uploads.
void spotify_suspend(bool suspend);
// The player's volume (0..100 %): reported to the Spotify app when a session starts (else the app
// shows 0 while we play at the player's level), and pushed to a running session.
void spotify_set_volume(int pct);
// A session is running (an app is connected to this device).
bool spotify_session_active(void);
typedef struct {
char artist[96], title[128], album[96]; // "" until the first track is audible
uint32_t duration_ms, position_ms; // position as the Spotify app sees it
bool paused;
} spotify_track_t;
// The current track of the running session. False without a session.
bool spotify_now_playing(spotify_track_t *t);
// Current state for status.spotify_state.
const char *spotify_state(void);
#ifdef __cplusplus
}
#endif