How to queue a Spotify track though API?


Hello,

 

I`ve build an integration for Sonos for my own voice controlled smart home system.

I`ve used the Control API for that… now I would like to queue tracks / playlists from Spotify. Can anyone give me a hint how to do that…?

 

I`ve already setup a Spotify integration, that enables me to search Spotify and get tthe item-id etc. But how can I queue those tracks from Spotify to my Sonos player?

 

Thanks

 

Carl


10 replies

Userlevel 7
Badge +22

Assuming you are using the Cloud API and not UPnP: you can’t. The Cloud API is pretty lame, and intended really for music services themselves, and they can of course queue their own items. However you cannot queue their items, you can only play Favorites and a few other limited things.

To do this over UPnP there are some hacks I have seen with url mangling that might work with Spotify. The real UPnP solution requires you to do some SMAPI calls to get the url and pass that to the players.

Thank you for the reply…

If it would be possible to control Sonos players through the Spoitify API, that would help too… but this way round Sonos player are excluded.

So we have tons of high priced music players… we have to different API to control them… but non of those APIs are able to queue music… grate!!! :-)

I`ve used upnp in the first version of my integration, but switched to the Control API because of a memory leak in the underling Intel upnp API… I think I´ll try to switch back to Upnp...

This Chrome extension used to work to add SoundCloud tracks to the Sonos queue.  No idea if it still works, but there might be some useful code there for your effort.

This Chrome extension used to work to add SoundCloud tracks to the Sonos queue.  No idea if it still works, but there might be some useful code there for your effort.

Thank you for the hint… there is a github repo for a node-js service that is able to queue spotify, apple etc. tracks… I think that uses upnp too… my project is based on c#, so I`ll have to port the required parts… 

 

I simply don´t understand what´s the problem here… (I know intellectual property etc.)… but… Sonos is connected to spotify so it can only play from spotify (or any other music service) through the registered  and authenticated service the customer has provided… what is the problem with an api that enables us to read the registred services and another service that accepts a service-id and a service related item-id (playlist, track, album etc.) to enqueue those items to the Sonos players queue?! 

Or the other way round… what is the problem if someone uses the spotify api to develop a special purpose spotify client and let that client control the sonos players that are linked to that spotify account?! 

Well, LMS does exactly that, using the UPnP and Spotty plugins.

"LMS"?

"LMS"?

https://github.com/Logitech/slimserver

Userlevel 7
Badge +20

SoCo-CLI’s ‘sharelink’ action allows Spotify tracks, albums and playlists to be added to the Sonos queue, using the internal UPnP interface:

https://github.com/avantrec/soco-cli#spotify-tidal-and-deezer-share-links

Alternatively, you could use the underlying SoCo library function from your own Python code:

http://docs.python-soco.com/en/v0.25.3/api/soco.plugins.sharelink.html

In each case, you’ll need the relevant URI from Spotify.

Thank you very much…

 

I've got it working... searching through spotify api... loading queu through upnp. But one little things does not work... when the player has a session that was initiated through the sonos pr spotify app, the queue that is created through upnp does not start (the sonos app shows "queu not used")…

 

Is there any way to switch to the "local queue"?

 

Carl

Userlevel 7
Badge +20

Sonos doesn’t automatically switch to playing from the queue when Items are added via uPnP. You have explicitly to start playback from the queue.

With SoCo-CLI, this is done using the ‘play_from_queue’ action (optionally followed by a queue item number).

See: https://github.com/avantrec/soco-cli#queue-actions

Other UPnP-based approaches will have something similar.

Reply