node-sonos-http-api
node-sonos-http-api copied to clipboard
Spotify playing an album (now) - question
Hello!
I am trying to extend a sonos implementation for the ESP8266 microcontroller (https://github.com/antonmeyer/sonos) with the spotify music service. Can anyone explain me the special procedure of adding a spotify album to the sonos queue?
https://github.com/jishi/node-sonos-http-api/blob/master/lib/actions/spotify.js Line 30-40, the "now" action is interesting. what does the code mean, especially the "promise" part?
And what is the difference between the following URI schemes for playing spotify playlists or albums "x-rincon-cpcontainer:0004206c" and "x-rincon-cpcontainer:0006206c"?
I already tried an implementation of playing a spotify album by clearing the queue, adding to queue (not working correct) and then start playing. And for single tracks my spotify implementation is already running...
Thanks for helping!
Hi. That exact portion of the code first check to see if the player is in "queue" mode, meaning it is playing form the queue (and not from a radio station, line-in etc). If it isn't, it changes the player into queue mode.
The next part just adds the selected uri to the queue, and then moves the queue cursor to the just added tracks (because now should instantly start playing whatever you queued). Since the tracks are queued right after the currently playing track, it basically just skips one step.
The promise parts are just for scheduling the task at hand right after the previous action has finished. It might look confusing if you aren't used to asynchronous code, but you can just think if it as a sequence of actions that will take place, so the flow is basically:
await player.coordinator.setAVTransport(`x-rincon-queue:${player.coordinator.uuid}#0`);
await player.coordinator.addURIToQueue(uri, metadata, true, nextTrackNo);
await player.coordinator.trackSeek(addToQueueStatus.firsttracknumberenqueued);
await player.coordinator.play();
The different uri schemes should have some effect on how Sonos is interpreting the metadata, but I don't recall exactly what is what, or what is needed. When I built this, I assume I tested it with both albums and playlists but I can't say for sure. Haven't tested it in a long time. Which one does work atm?
Thanks for your quick response! I will test the described procedure. Right now adding an album uri is not working...
Hi, I have the same problem atm. Did you find a solution?