我正在制作Spotify应用程序。播放歌曲时,应用程序将显示如下相册:
http://s17.postimage.org/votnl6epp/Schermafbeelding_2012_04_04_om_22_47_54.png
我已阅读播放列表文档(https://developer.spotify.com/technologies/apps/docs/beta/c49e02a392.html),但我无法弄清楚如何订阅相册。
任何人都可以帮助我吗?
答案 0 :(得分:3)
如何订阅播放列表?
/* 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!");
});
});
HTML输入将是:
<input type="button" id="subscribe" value="Subscribe" />
答案 1 :(得分:1)
你不能,你需要从专辑创建一个播放列表,这是我如何继续:
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();
});
当然,您必须继续使用HTML部分。
希望它会有所帮助
热罗