How to add album as playlist?

Go To StackoverFlow.com

0

Im making a Spotify application. When you play a song, the application will show the album like this:

http://s17.postimage.org/votnl6epp/Schermafbeelding_2012_04_04_om_22_47_54.png

Ive read the Playlist documentation (https://developer.spotify.com/technologies/apps/docs/beta/c49e02a392.html), but I cant figure out how to subscribe on a album.

Can anyone help me?

2012-04-04 20:51
by 0846277


3

How to subscribe to a playlist?

/* 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');

$("#subscribe").click(function(playlist){
    var playlist = models.Playlist.fromURI("spotify:user:spotify:playlist:3Yrvm5lBgnhzTYTXx2l55x");
    playlist.subscribed = true;

    playlist.observe(models.EVENT.CHANGE, function() {
        console.log("Playlist is subscribed!");
    });
});

The HTML input would be:

<input type="button" id="subscribe" value="Subscribe" />
2012-04-07 13:17
by Mick D
In that case, you need to create a user playlist manually and then to subscribe, was thinking you wanted to do it dynamically - Geraud Puechaldou 2012-04-07 21:07


1

You can't, you need to create a playlist from the album, here is how I proceed :

alb = m.Album.fromURI(uri, function(album) { 
pl.name = album.name;
$.each(album.tracks,function(index,track){
pl.add(m.Track.fromURI(track.uri)); 
});         
var player = new v.Player();
player.track = pl.get(0);
player.context = album;
var saveButton = "<button id='savePlaylist' class='add-playlist sp-button sp-icon' <span class='sp-plus'></span>Add as Playlist</button>";
var list = new v.List(album , function(track) {
return new v.Track(track, v.Track.FIELD.STAR | v.Track.FIELD.SHARE | v.Track.FIELD.NAME  | v.Track.FIELD.DURATION);
});

$("xxx").live('click',function(e){
var myAwesomePlaylist = new m.Playlist(album.artist.name + " - " + pl.name);
$.each(pl.data.all(),function(i,track){
myAwesomePlaylist.add(track);
});
e.preventDefault();
});

Of course you have to proceed with the HTML part.

Hope it will help

Geraud

2012-04-05 07:09
by Geraud Puechaldou
Ads