在SoundCloud自定义播放器中获取当前曲目信息

时间:2012-12-08 19:10:13

标签: soundcloud

我差不多已经完成了创建我的声音云流媒体自定义播放器,但我希望选择添加当前正在播放的歌曲的标题和艺术家。

现在我有这个:http://hellkeepers.com/music/examples/sc-player-minimal.html

但我似乎无法弄清楚在哪里可以找到当前的曲目信息。

1 个答案:

答案 0 :(得分:0)

获取图像和标题,您可以使用此代码:

//get element by id from your iframe
var widget = SC.Widget(document.getElementById('soundcloud_widget'));
widget.getCurrentSound(function(music){
    artwork_url = music.artwork_url.replace('-large', '-t200x200');
    $('#song1').css('background', 'url(\"'+artwork_url+'\") ');
    //write the title in a div with the id "title"
    document.getElementById('title').innerHTML = music.title;
});

通常你会得到一个链接" -large"最后,尺寸为100x100。如果你想要其他尺码,你必须用" .replace"来改变结尾。像我一样。您可以在此处找到可用尺寸的列表:

https://developers.soundcloud.com/docs/api/reference#tracks(我的尺寸200x200未列出,但有效。也许有更多尺寸,例如每百px。)

使用:

widget.getDuration(function(duration) {
    alert(duration);
}

你有歌曲的长度(毫秒)

使用:

widget.getPosition(function(position) {
    alert(position);
}

你有这首歌的实际效果,以毫秒为单位。你必须运行一个循环来获得实际时间的每一秒。也许你必须计算毫秒到秒和分钟。

迟到但更好,从来没有我的回答:D

相关问题