【发布时间】:2014-02-16 16:11:58
【问题描述】:
我正在尝试编写一个脚本,一旦按下按钮,它将显示来自 SoundCloud 的歌曲的持续时间。我在 API 上也遇到了一些麻烦。我已经阅读并重新阅读了有关某些“回调”传递参数的行,但我仍然不明白。 “正因为如此,每个 getter 方法都接受一个回调函数作为参数,当调用该参数时,将获得 getter 方法的返回值。”
这是我的代码所在。我知道它不漂亮,但我只是想让这该死的东西发挥作用。
<!doctype html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://w.soundcloud.com/player/api.js"></script>
<script>
$(document).ready(function() {
var widget = SC.Widget(document.getElementById('playing'));
widget.bind(SC.Widget.Events.READY, function() {
console.log('Ready...');
});
$('button').click(function() {
widget.getDuration(function(sound));
});
});
function sound(var time) {
document.write(time);
}
</script>
</head>
<body>
<iframe id="playing"
width="500"
height="400" scrolling="no"
frameborder="yes"
src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/66816173&auto_play=false&hide_related=false&visual=true">
</iframe>
<button>Play / Pause</button>
</body>
</html>
【问题讨论】:
标签: javascript soundcloud