Spotify应用程序 - 获取播放列表轨道 [英] Spotify Apps - Getting Playlist Tracks

查看:109
本文介绍了Spotify应用程序 - 获取播放列表轨道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Spotify应用程序并希望获得播放列表的曲目。有功能 playlist.tracks 但这似乎是缓存并得到错误的曲目列表。它也应该很慢,不建议在API文档中使用。但是我有什么其他选择来获得播放列表的曲目?目前我正在使用 playlist.tracks 一次并通知我的后端跟踪列表。

I'm developing a Spotify app and want to get the tracks for a Playlist. There's the function playlist.tracks but that seems to be cached and gets the wrong list of tracks. It's also supposed to be slow and not recommended to be used in the API documentation. But what other option do I have to get a Playlist's tracks? At the moment I'm using playlist.tracks once and informing my back-end of the track list.

谢谢。

推荐答案

对于1.0 API:

require([
  '$api/models'
], function (models) { 

 var addList = function(list) {
    list.load('tracks').done(function(list) {
        list.tracks.snapshot().done(function(trackSnapshot){
            var tracks = trackSnapshot.toArray();
            for(var i=0; i<tracks.length; i++) {
                addTrack(tracks[i]);
            }
        });
    });
 }

 var addTrack = function(track) {
    track.load('name','artists').done(function(track) {
        var artists = track.artists;
        var artistsList = [];
        for (var i=0; i<artists.length; i++) {
            artistsList.push(artists[i].name);
        }
        // Print out info if desired
        var addedTrackRow = document.createElement('p');
        addedTrackRow.innerHTML = "Added track: " + artistsList.join(', ') + ' - ' + track.name;
        document.getElementById('addedTracks').appendChild(addedTrackRow);

    });
 }

 exports.addList = addList;
 exports.addTrack = addTrack;
}

// Example of use:
addList(models.Playlist.fromURI(...))
addTrack(models.Track.fromURI(...))

我已经按照上面的使用进行了测试,它确实有效。

I've tested it as used above, and it works.

我花了一些时间自己寻找答案,我也在寻找如何访问列表中的曲目,即使它在在元数据部分下的github 上提供的教程应用程序; 从艺术家,专辑,曲目或播放列表中获取元数据。

I spent some time looking for an answer to this myself, and I also were looking for how to access tracks within a list even though it's explained in the tutorial-app available on github under the "Metadata"-section; "Get metadata from an artist, album, track or playlist".

我希望这是有用的。

这篇关于Spotify应用程序 - 获取播放列表轨道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆