Soundcloud:无法设置属性' id'尝试播放歌曲时未定义

时间:2012-04-30 14:03:03

标签: javascript soundcloud soundmanager2

下面的代码是从CoffeeScript编译的,希望它仍然可读

(function() {

  $(function() {
    var PLAYLIST_ID, SOUNDCLOUD_ID, tracks, tracks_ready, tracks_total;
    SOUNDCLOUD_ID = '6d5064768cc29c71e1f66691f435589a';
    PLAYLIST_ID = '1768866';
    SC.initialize({
      client_id: SOUNDCLOUD_ID
    });
    tracks = [];
    tracks_total = 0;
    tracks_ready = function() {
      return tracks[0].play();
    };
    return SC.get('/playlists/' + PLAYLIST_ID, function(pl) {
      var track;
      track = pl.tracks[0];
      return SC.stream('/tracks/' + track.id, function(sound) {
        tracks.push(sound);
        return tracks_ready();
      });
    });
  });

}).call(this);

代码在jquery之后执行,并且包含“//connect.soundcloud.com/sdk.js”。

它给出了Uncaught TypeError:无法使用以下跟踪设置undefined的属性'id':

window.SC.SC.Helper.merge.stream - window.SC.SC.Helper.merge.whenStreamingReady - some SM2 stuff

1 个答案:

答案 0 :(得分:2)

哦,SC.stream中似乎有一个错误。快速解决方法是传递可选的选项对象: SC.stream('/ tracks /'+ track.id,{},功能(声音)......) 确保尽快找到解决办法。