Files
ReSkate/Extension/Music/spotify_device.h
T
AyeZeeBB 48a9cb8f5b Music: Spotify, YouTube Music and External Audio through the in-game player
Three outside sources can now be played through the game's own music
player. Each has its own row in the music screen, shown only when it is
set up, with tiles that behave like the game's playlists: track name,
cover, pause, next, and pressing a row to start that track.

How the sound gets in
- The game's song decoder is hooked. While one of these tiles is on, the
  audio of the game song behind it (its "carrier") is replaced, block by
  block, with the outside source's audio. The game's volume, fades and
  pausing still apply.
- Rows are songs of our own registered with the game's music registry
  (copies of a real song's asset with their own artist and title), so no
  game song is borrowed or renamed to list a track.

Spotify
- The game is a Spotify Connect device ("ReSkate"), built on librespot
  and linked into ReSkate.dll (SpotifyHelper/, Rust). Audio, track info
  and controls come straight from Spotify. Needs Premium.
- Optional sign-in through the Web API lists the player's playlists and
  Liked Songs as tiles with their tracks.
- librespot can no longer end the process (it does so on a free account
  and on playback errors); only its thread is stopped.

YouTube Music
- Videos and playlists added by link. yt-dlp is fetched on request into
  <Local AppData>\ReSkate\bin and checked against its published sums;
  decoding is done in the DLL, so no ffmpeg.
- Private and age-restricted songs: cookies.txt or a browser's sign-in,
  with QuickJS fetched as the JavaScript runtime yt-dlp then needs
  (Node.js is used instead when installed).

External Audio
- Any app's sound, captured per process from Windows, with the app's own
  output turned down while it plays through the game.

Setup page
- "spotify setup" opens http://127.0.0.1:8421/: device status, sign-ins,
  YouTube links and tools, the external app, loudness. Loopback only;
  changes are accepted from its own page only.

Also
- Speakers in the world play the tile's audio; grabbing one keeps the
  player on their tile.
- Playlists added while the game runs are sent to the music screen live.
- MUSIC-SETUP.md: setup guide for players.

Building the Spotify device and the YouTube decoder needs cargo; without
it ReSkate.dll builds without them.
2026-10-12 03:16:36 -05:00

39 lines
2.0 KiB
C++

#pragma once
#include "external_player.h"
#include <string>
// The game as a device in the player's Spotify app ("ReSkate"), by way of ReSkateSpotify.exe
// (SpotifyHelper/, built on librespot), which is started beside ReSkate.dll. Spotify plays to
// it as it would to a speaker: its sound comes to the game as it is (app_audio_capture.h's
// buffer is filled with it, in the place of what is captured from the Spotify app), with the
// song's name and cover, and the game's play, pause and next go to it.
//
// Who the account is comes from the Spotify app: the player picks "ReSkate" among its devices
// once, on the same network, and it is kept. Until an account is on it, the Spotify station
// goes on working through the Spotify app on this computer (external_player.h).
namespace dingosdk::spotify_device {
// Starts the helper, once; nothing when it is not beside the DLL.
void start() noexcept;
// Whether a Spotify account is on the device: it is then what the station plays and shows.
bool connected() noexcept;
// Whether it has an account or one kept to sign in with: the player uses Spotify here.
bool in_use() noexcept;
// What it is playing, as external_player gives it.
external_player::Track now();
std::uint64_t revision() noexcept;
void send(external_player::Command command) noexcept;
// Has it play here, taking over from wherever Spotify is playing.
void activate() noexcept;
// The plain Spotify station: whatever Spotify was playing goes on here; when it was playing
// nothing, the player's Liked Songs are played, in no order.
void start_radio() noexcept;
// A playlist ("spotify:playlist:..."), at one of its tracks when given; or these tracks, at one.
void load(const std::string& context, const std::string& track = {}) noexcept;
void load_tracks(const std::string& tracks_spaced, unsigned index) noexcept;
// The library asked for the whole program to be ended (music_inject.cpp stops that): the device
// is stopped for this run, and an account it will not take is forgotten.
void library_gave_up() noexcept;
// For the console.
std::string status();
}