squeezenode icon indicating copy to clipboard operation
squeezenode copied to clipboard

how I can load a playlist spotify on a player and play song ?

Open angelz07 opened this issue 10 years ago • 5 comments

hello,

I try to load a play list in a player (with his player id) and start playing list song of the playlist but I dont see how do that :-)

can you help me

now I test this code but ...

exports.play_playlist = function (playlist_uri) { console.log(playlist_uri)

//subscribe for the 'register' event to ensure player registration is complete

squeeze.on('register', function () {
    //you're ready to use the api, eg.
    squeeze.getPlayers(function (reply) {
        console.dir(reply);
    });
});
squeeze.on('register', function () {
    //we only need a couple (5) of search results

            //Now let's play the song with our player
            playerIdByName(config.nom_player, function (pl) {
                if (reply.ok) {
                    squeeze.apps.spotify.loadToPlaylist(playlist_uri, pl.playerId, function (reply) {
                        if (!reply.ok) {
                            console.dir(reply);
                        }
                        //if needed, let's adjust the volume
                        squeeze.players[pl.playerId].setVolume(40);
                    //Enjoy listening
                    });
                }
            });

});

}

can you help me please ?

angelz07 avatar Feb 01 '15 13:02 angelz07

Glad to help,

What is playlist_uri and how do you get it? Can you post console.dir(reply) of this loadToPlaylist?

piotrraczynski avatar Feb 01 '15 22:02 piotrraczynski

I've just tested adding playlist and it seems to work. I admit that I haven't implemented playlist querying in the library but when I copied playlist URL from spotify desktop app (right click on playlist and 'copy spotify URI') and passed it as string argument to loadToPlaylist it works just fine, is your playlist url something like this?

spotify:user:youruserid:playlist:66VOb4xsC9yEk7X5DXVXsW

piotrraczynski avatar Feb 01 '15 22:02 piotrraczynski

helle thanks for reply,

ok so the code I have put is ok ?

I use this type of uri : https://api.spotify.com/v1/users/spotify/playlists/3jtuOxsrTRAWvPPLvlW1VR/tracks

angelz07 avatar Feb 02 '15 02:02 angelz07

Hi,

The code looks ok, (unless player with this name doesn't exist) but the URI you provided probably won't work. Do you have access to standalone, desktop Spotify client (works on Windows/Linux and MAC too I guess)? You're trying to open http URL (probably from web client) and this is not going to work (I haven't tried that but you did and it didn't work). Valid Spotify URI for a playlist should be sth like this:

eg. spotify:user:user_id:playlist:66VOb4xsC9yEk7X5DXVXsW

Try to copy URI from Desktop player instead of URL from web player, and you should be ok. If you don't have access to desktop player, you can try to change my example. Type your user id as user_id above and exchange the playlist hash in my example to yours (3jtuOxsrTRAWvPPLvlW1VR). If Spotify URI templates are consistent (which I assume is true) it should work.

BTW1, I'm working on extending Spotify to support playlist querying, etc. Stay tuned I plan to release new version soon.

BTW2, Try to log the reply also if request failed (reply.ok is false) to see if you even get to this loadToPlaylist function.

Let me know if it started to work for you. If not we'll burn the issue down to the ground.

piotrraczynski avatar Feb 02 '15 09:02 piotrraczynski

hi,

any update?

dcjona avatar Oct 07 '20 10:10 dcjona