james
james

Reputation: 67

How autoplay top tracks in spotify?

I have created a button and have onclick event on that. Now i want to play and pause my top track but cant play that. Anyone can help ?

      var sp = getSpotifyApi();
      var models = sp.require('$api/models');
      var myAwesomePlaylist = new models.Playlist("My Awesome Playlist");
      myAwesomePlaylist.add(models.player.track);
      myAwesomePlaylist.add("spotify:track:6PvpKM4BW48ic8cbM4Vxcg");

here is my code this is being adding the playlist but if I'm manipulating it, like

myAwesomePlaylist.play("spotify:track:6PvpKM4BW48ic8cbM4Vxcg");

It doesn't work!

Upvotes: 1

Views: 761

Answers (1)

iKenndac
iKenndac

Reputation: 18776

The playlist doesn't play — you need the player for that.

models.player.play(track, playlist, 0);

Or, if you just want to play/pause:

models.player.playing = true; / models.player.playing = false;

Documentation here. If this isn't what you meant, please be more clear with your question — the code you pasted in is copied straight from an example in the documentation.

Upvotes: 1

Related Questions