SC.stream - 如何在开始新轨道之前删除当前轨道?

时间:2014-02-21 15:32:15

标签: stream soundcloud

我正在使用播放列表将网址提供给SC.stream。但是当我开始下一首曲目时,我无法弄清楚如何删除之前的声音。 我的功能看起来像这个

function stream (url){
SC.stream(url, function(sound){
sound.play()
)}
}

我知道我错过了删除旧声音的行,但我不知道如何删除它以及放置行的位置。 非常感谢你

2 个答案:

答案 0 :(得分:1)

很抱歉这已经很晚了,但我最近发现的一个简单的解决方案是在我的下一个和上一个按钮上使用.destruct()。

function stream (url){
  SC.stream(url, function(sound){
    sound.play();
    $('#nextbutton, #prevbutton').click(function(){
      sound.destruct();
    });
  )};
}
stream (url);

请注意,我使用了jQuery,但我认为如果正确引用按钮,.destruct()方法仍然可以在纯js中使用。

答案 1 :(得分:0)

您不需要删除当前曲目,只需停止播放,如果是,则加载新曲目。

SC.initialize({
  client_id: 'MY_CLIENT_ID'
});

var playing = false;

play = function(trackId){
  if(playing){
     // Stop the current sound
     SC.sound.stop();
  }

  // Play the new one
  SC.stream("/tracks/" + trackId, function(sound){
    // Store the sound object inside the SC object which belongs 
    // to the global scope so that it can be accessed out of the 
    // scope of this callback
    SC.sound = sound;
    SC.sound.play();
    playing = true;
  });
}