Transfer playback between your devices using Spotify Connect. To be used with Google Assistant, Flic button etc.
This example uses Google Cloud Functions, but can be deployed elsewhere too.
- Install and initialize Google Cloud Functions as described on https://cloud.google.com/functions/docs/tutorials/http
- Authenticate Google Cloud by running
gcloud auth login- Configure Google Cloud project (if authentication didn't set you up with the correct one).
gcloud config set project PROJECT_ID- Install dependencies with
npm install- Create an application on Spotify for Developers.
- Add redirect uri
http://localhost:8888/callback - Create a
config.jsonfile (based onconfig.default.json) and updateCLIENT_IDandCLIENT_SECRETfrom the Spotify application you just created. - Start configuration by running
node setup.js- (Optional) Add keywords to your devices in
config.json(lowercase)
Test your configuration by running
npm run testThis should start playback to the first device in your list. It can also take an argument of a device:
npm run test -- "MySpeaker"To deploy to Google Cloud Functions run
npm run deploySet up a new WebHook trigger with the URL displayed after deploy, something in the form of
https://{YOUR-REGION}-{YOUR-PROJECT-ID}.cloudfunctions.net/playOnDevice
Select method POST, Content-Type to application/json and set body to:
{
"device": "{{TextField}}",
"secret": "{YOUR-SECRET-IN-CONFIG.JSON}"
}All calls should be made with POST method.
Activate playback on given device
secret Your shared secret for authentication
device The name (or one of the keywords) of the device to move playback to
Skip to next track
secret Your shared secret for authentication
Skip to previous track
secret Your shared secret for authentication
Pause playback
secret Your shared secret for authentication