传递给Soundmanager(通过Soundcloud JS SDK)的选项未被使用

时间:2013-11-26 01:24:27

标签: javascript soundcloud

我设置了一个小代码,here来展示我的问题。

创建一个对象来保存一些选项,这些选项作为参数传递给stream方法。

var custom_options = {
  multiShot: false
  , onplay: function() {
    SC_STATE.playing();
    SC.playing = true;
  }
  , whileplaying: function() {
    SC_STATE.updating(SC.current_track.position, SC.current_track.durationEstimate);
  }

},
SC_STATE = {
  playing : function(id) {
        this.el.unbind('click').click( function() {
            SC.current_track.pause();
    });     
  }
  , updating : function(position, estimate) {
    var percentage = (position / estimate) * 100;
        this.played.css('width', this.round(percentage) + "%");
  }
}

声音播放时,#sc-played元素的宽度应该会扩大,但事实并非如此!这个功能,

options = { url: "http://soundcloud.com/tokyospeirs/flightless-bird" };
SC.get('/resolve', options, function(track) {
    SC.stream('/tracks/' + track.id, custom_options, function(track) {
        track.play() 
    });
});

被告知要使用上面的custom_options,其中包含whileplaying方法。这是在不久前的工作。我失踪的sc sdk有什么新东西?还有其他人遇到过这个问题吗?

1 个答案:

答案 0 :(得分:0)

根据their git history,Soundcloud最近提交了对其SDK的更改。

现在使用AudioManager代替SoundManager2播放曲目,因此API已更改。

如果您希望在曲目开始播放时收到通知,请使用以下代码:

SC.stream('/tracks/' + track.id, custom_options, function(track){
  track.on("stateChange", function(evt){
    if (evt=="playing") // do your business here
  });
});

如果您希望定期收到有关播放曲目进度的通知,请使用:

  track.on("positionChange", function(pos, len){
    // do your thing here
  });