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

James L.
Retired Community Staff
March 19, 2021

Hi @Manatee19, welcome to the community.

 

Everything you’ve just described already exists on Sonos though one means or another. If you are looking to build your own controller app then I will point you in the direction of our Sonos Developer site that includes all the support and documention you need to integrate into the Sonos API. We also have a tag on Stack Overflow for any development questions.

 
 
 
 
 
Mark good posts by pressing the like button, and select the best answer on questions you've asked to help others find solutions.
Belly M
March 19, 2021

I don’t know anything about about .NET but Python in conjunction with SoCo is very powerful.

controlav
Lead Maestro
March 19, 2021

Music playback is via UPnP, specifically AVTransport1.SetAVTransportURI. However the kicker is getting the correct url for a Spotify stream.

To do that you need to be a SMAPI client, and you can read about SMAPI at the link in the previous post.

However the real tricky bit is to get the user’s credentials from the Sonos system so you can authenticate with the Spotify SMAPI server. That requires you to decrypt the encrypted authentication data.

A few open source projects have avoided this problem by mixing the public Spotify API with UPnP, but this works with Spotify only (and maybe a couple of other services too). I am not aware of an open source project that includes the necessary decryption to work with every music service.

On the other hand playing a file from a USB stick is a lot more straight-forward. Just run a small web server and pass its url to SetAVTransportURI.

Author of the leading independent Sonos apps for Android, MacOS, iOS, Windows and Xbox.
Manatee19Author
Contributor I
March 19, 2021

Music playback is via UPnP, specifically AVTransport1.SetAVTransportURI. However the kicker is getting the correct url for a Spotify stream.

To do that you need to be a SMAPI client, and you can read about SMAPI at the link in the previous post.

However the real tricky bit is to get the user’s credentials from the Sonos system so you can authenticate with the Spotify SMAPI server. That requires you to decrypt the encrypted authentication data.

A few open source projects have avoided this problem by mixing the public Spotify API with UPnP, but this works with Spotify only (and maybe a couple of other services too). I am not aware of an open source project that includes the necessary decryption to work with every music service.

On the other hand playing a file from a USB stick is a lot more straight-forward. Just run a small web server and pass its url to SetAVTransportURI.

Actually I just need spotify and nothing else and the process of getting the secret and key (if they will be needed) will be done initially and manually by a technician, but after that it’s all dark. Im not sure If I need to get these keys: direct-control-authorize in order to control it. Or I can control it maybe just getting the spotify keys and somehow getting the songs-URI

Manatee19Author
Contributor I
March 19, 2021

I don’t know anything about about .NET but Python in conjunction with SoCo is very powerful.

I will take a look at it

Manatee19Author
Contributor I
March 19, 2021

Hi @Manatee19, welcome to the community.

 

Everything you’ve just described already exists on Sonos though one means or another. If you are looking to build your own controller app then I will point you in the direction of our Sonos Developer site that includes all the support and documention you need to integrate into the Sonos API. We also have a tag on Stack Overflow for any development questions.

 
 
 
 
 

Actually I dont want to create a full Controller I just want to retrieve the playlist of the user and play a song, nothing else. What do you think I need to accomplish this?
Thank you

controlav
Lead Maestro
March 20, 2021

Hi @Manatee19, welcome to the community.

 

Everything you’ve just described already exists on Sonos though one means or another. If you are looking to build your own controller app then I will point you in the direction of our Sonos Developer site that includes all the support and documention you need to integrate into the Sonos API. We also have a tag on Stack Overflow for any development questions.

 

Actually I dont want to create a full Controller I just want to retrieve the playlist of the user and play a song, nothing else. What do you think I need to accomplish this?
Thank you

What kind of playlist exactly? If you want to use a Sonos Playlist, you can do that using the well documented Sonos Cloud API. If you want a Spotify playlist then I would use SMAPI, but you can’t as you don’t have the required secrets. I’ve never looked at the Spotify API, but I think others have figured out how to get the urls from that into a form that a Sonos speaker will accept. Good luck.

Author of the leading independent Sonos apps for Android, MacOS, iOS, Windows and Xbox.
Manatee19Author
Contributor I
March 24, 2021

Hi @Manatee19, welcome to the community.

 

Everything you’ve just described already exists on Sonos though one means or another. If you are looking to build your own controller app then I will point you in the direction of our Sonos Developer site that includes all the support and documention you need to integrate into the Sonos API. We also have a tag on Stack Overflow for any development questions.

 

Actually I dont want to create a full Controller I just want to retrieve the playlist of the user and play a song, nothing else. What do you think I need to accomplish this?
Thank you

What kind of playlist exactly? If you want to use a Sonos Playlist, you can do that using the well documented Sonos Cloud API. If you want a Spotify playlist then I would use SMAPI, but you can’t as you don’t have the required secrets. I’ve never looked at the Spotify API, but I think others have figured out how to get the urls from that into a form that a Sonos speaker will accept. Good luck.

The spotify playlist of the account linked using the sonos S1 App. Anyway I was able to get the token to send request using the API but when I tried to ask for households it return an empty list. Maybe is the ZP100 too old?

controlav
Lead Maestro
March 25, 2021

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

Author of the leading independent Sonos apps for Android, MacOS, iOS, Windows and Xbox.
Manatee19Author
Contributor I
March 25, 2021

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

Well I think I am. I was calling some random stuff in order to see if I will receive something and I understood that household is like the device.

My final goal is to be able to get the Spotify play lists and reproduce songs from them on my sonos device. Until now I was only able to get the auth token and now I can make all API calls, but I don't know which one can help me.