如何通过Soundcloud API重复一首歌

时间:2014-06-28 00:51:10

标签: javascript jquery soundcloud repeat

我正在制作基于SoundCloud API的自定义音乐播放器。我想要一个重复按钮,所以按下它时,将重复当前的歌曲。据我所知,SoundCloud不提供任何重复方法,但它有一些position()方法可以获得歌曲的正确位置。我无法使这种方法有效。但是你有什么建议重复当前的流歌吗?

到目前为止我的代码:

function playIt(){
var sound = SC.stream("/tracks/293", function(sound){
    sound.play();

});
}
function repeat(){
    var sound = SC.stream("/tracks/293", function(sound){
    console.log(sound.position);
    });
}

演示:http://jsfiddle.net/danials/zcN7G/23/

有什么想法吗? 提前致谢

1 个答案:

答案 0 :(得分:4)

var repeatSong = function() {
    this.play({onfinish: repeat});
};

var sound = SC.stream("/tracks/293", function(sound){
    sound.play({onfinish: repeatSong});        
});

http://jsfiddle.net/G5RdX/1/