Skip to main content
Contributor I
March 18, 2021

How to implement Spotify

  • March 18, 2021
  • 22 replies
  • 1242 views

Hi everyone, I am a developer and Im building a .NET app in order to play music from Sonos ZP100 using Spotify. Or alternatively with music plugged into an USB. I tried using the UPnP protocol but it doesn seem to be the right way to reproduce songs. I am only able to play pause stop seek next previous and volume controls but nothing else. Do somebody know how to do something similar?
The perfect example is the SONOS S1 app that after linking spotify account can reproduce songs

This topic has been closed for further comments. You can use the search bar to find a similar topic, or create a new one by clicking Create Topic at the top of the page.

22 replies

Manatee19Author
Contributor I
March 25, 2021

I am confused. What are you asking for Households exactly? Spotify??

I was able to finally call the favorites and the sonos playlist, now im looking on how to receive playlist from spotify and play a specific song in the playlist

March 25, 2021

Spotify app on any phone to target Sonos speaker. Job done.

Manatee19Author
Contributor I
March 25, 2021

Spotify app on any phone to target Sonos speaker. Job done.

Eh eh eh, I will like it if it was in that way but we are developing an app that includes all the service between those there is sonos with playback of spotify songs…. Do youhave any other idea?

Manatee19Author
Contributor I
March 25, 2021

I am confused. What are you asking for Households exactly? Spotify??

I want to do the same stuff that SONOS S1 app does, connect the spotify service somehow and play audio on sonos. There is a way using API (reading on stack it seems that there isnt a way to do this), if not what should I use to do this? UPnP, using loadAudioClip and grab in some way a streamUrl from Spotify?
Super thank you boss

controlav
Lead Maestro
March 26, 2021

I am confused. What are you asking for Households exactly? Spotify??

I want to do the same stuff that SONOS S1 app does, connect the spotify service somehow and play audio on sonos. There is a way using API (reading on stack it seems that there isnt a way to do this), if not what should I use to do this? UPnP, using loadAudioClip and grab in some way a streamUrl from Spotify?
Super thank you boss

  1. Obtain key and token for the user’s Spotify account from the Sonos system (very hard)
  2. Use SMAPI to connect to Spotify and enumerate the playlists (easy if you know REST)
  3. Pick one and take the url and pass it to AVTransport1.SetNextAVTransport (UPNP call to speaker) (trivial if you know UPnP)

No idea if you could replace #3 with loadAudioClip

Author of the leading independent Sonos apps for Android, MacOS, iOS, Windows and Xbox.
pwt
Virtuoso
March 26, 2021

Hi everyone, I am a developer and Im building a .NET app in order to play music from Sonos ZP100 using Spotify. Or alternatively with music plugged into an USB. I tried using the UPnP protocol but it doesn seem to be the right way to reproduce songs. I am only able to play pause stop seek next previous and volume controls but nothing else. Do somebody know how to do something similar?
The perfect example is the SONOS S1 app that after linking spotify account can reproduce songs

Just to note that playing local files (e.g., from USB drives) on Sonos is one of the features offered by SoCo-CLI. It works just as @controlav describes, but is implemented in Python:

https://github.com/avantrec/soco-cli#audio-files-on-the-local-filesystem

Also, we’re currently working on music service (re)enablement in SoCo. It’s tricky, but once it’s available, I’ll add it to SoCo-CLI.

https://github.com/SoCo/SoCo/pull/763

4 x P:5 | Sub | 4 x P:1 | 3 x Connect | 2 x Boost | Connect:Amp | 2 x One | Amp | Move | Port | Era 300
Manatee19Author
Contributor I
March 26, 2021

Hi everyone, I am a developer and Im building a .NET app in order to play music from Sonos ZP100 using Spotify. Or alternatively with music plugged into an USB. I tried using the UPnP protocol but it doesn seem to be the right way to reproduce songs. I am only able to play pause stop seek next previous and volume controls but nothing else. Do somebody know how to do something similar?
The perfect example is the SONOS S1 app that after linking spotify account can reproduce songs

Just to note that playing local files (e.g., from USB drives) on Sonos is one of the features offered by SoCo-CLI. It works just as @controlav describes, but is implemented in Python:

https://github.com/avantrec/soco-cli#audio-files-on-the-local-filesystem

Also, we’re currently working on music service (re)enablement in SoCo. It’s tricky, but once it’s available, I’ll add it to SoCo-CLI.

https://github.com/SoCo/SoCo/pull/763

Im bonded to C# I cant use python unfortunately

Manatee19Author
Contributor I
March 26, 2021

I am confused. What are you asking for Households exactly? Spotify??

I want to do the same stuff that SONOS S1 app does, connect the spotify service somehow and play audio on sonos. There is a way using API (reading on stack it seems that there isnt a way to do this), if not what should I use to do this? UPnP, using loadAudioClip and grab in some way a streamUrl from Spotify?
Super thank you boss

  1. Obtain key and token for the user’s Spotify account from the Sonos system (very hard)
  2. Use SMAPI to connect to Spotify and enumerate the playlists (easy if you know REST)
  3. Pick one and take the url and pass it to AVTransport1.SetNextAVTransport (UPNP call to speaker) (trivial if you know UPnP)

No idea if you could replace #3 with loadAudioClip

  1. I have access to user’s spotify account (in order to create key and secret) so I guess the point 1 can be skipped?
  1. I read the SMAPI doc here: SMAPI but there isnt a call that retrieve an URL except for the getMediaURI that seems to return an URI to the stream, but there isnt the Endpoint indicated in the SMAPI.
  2. I dont know UPnP and I was searching for some lib for C# but I dont find nothing easily to use. Can you give me an example of URL to pass to the SetNextAVTransport?

    If can help I have full access to SONOS and SPOTIFY user’s account
    Thank you, you are kind and helpful.
controlav
Lead Maestro
March 28, 2021
  1. I don’t think you can take the key and secret from the Spotify and pass them to SMAPI, but I never tried it, so worth a shot
  2. getMetadata is the call you need, starting at “root” and navigate through that so you can get to the user’s playlists. Once you have done that once, you will probably find a fixed id for users playlists and can go straight to it.
  3. There are lots of UPnP APIs for C# around (I have not used any of them), and if on Windows you can use the built-in OS support for it (which I last used about a decade ago).

Actually i misspoke: for a Spotify playlist you will need to AddURIToQueue not SetNextAVTransport. The URI would be something like "x-rincon-cpcontainer:0006008cspotify%3aplaylist%3a3irbM1vEqph2KusCP" and the metadata would be a basic DIDL-lite structure containing an id similar to the url (but different). All of this is trivial to see by taking a network capture of the Sonos app starting a Spotify playlist.

Author of the leading independent Sonos apps for Android, MacOS, iOS, Windows and Xbox.
Manatee19Author
Contributor I
March 30, 2021
  1. If I cant pass data to the SMAPI how can I use this SMAPI? I look for an endpoint of the SMAPI and I didnt find it. The unique sneak I found is this:

    but this page is no longer accessible. If I understand correctly the SMAPI server is something that I need to create and host and then this server redirect the REST call to the music service using their API, is it correct? That’s why there isnt an endpoint on SMAPI DOC?

  2. Ok

  3. I tried some but no documentation at all so it’s tricky

  4. You talk about capture a frame form the sonos app, how can I accomplish this, I was thinking about wireshark but my pc is wired so Im not sure I can get the frame that start from my phone and I guess they are encrypted.
    Thank you