Created
February 11, 2012 18:01
-
-
Save mager/1803331 to your computer and use it in GitHub Desktop.
Spotify Apps API - Play a list of songs (JS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Instantiate the global sp object; include models & views */ | |
var sp = getSpotifyApi(1); | |
var models = sp.require("sp://import/scripts/api/models"); | |
var views = sp.require("sp://import/scripts/api/views"); | |
/* Create an array of tracks from the user's library */ | |
var tracks = models.library.tracks; | |
/* Create a temporary playlist and fill it with tracks | |
* from the previous query */ | |
var tempPlaylist = new models.Playlist(); | |
for(var i=0;i<20;i++) { | |
var track = models.Track.fromURI(tracks[i].data.uri); | |
tempPlaylist.add(track); | |
} | |
/* Create a Player() object and fill it with content | |
* from the temporary playlist object created earlier */ | |
var player = new views.Player(); | |
player.track = tempPlaylist.get(0); | |
player.context = tempPlaylist; | |
/* Pass the player HTML code to the #player <div /> */ | |
$('#player').append(player.node); | |
/* Create a "view" for the playlist and pass the list | |
* code to the #player <div /> */ | |
var playlist = new views.List(tempPlaylist); | |
$('#player').append(playlist.node); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment