【发布时间】:2013-01-22 19:37:57
【问题描述】:
我正在为 Soundcloud HTML5 Widget API 苦苦挣扎。方法和事件工作正常,但我无法记录 getter。我一直在查看 Soundcloud API 文档,但找不到问题所在。 Soundcloud Playground 运行良好,但他们在博客 http://developers.soundcloud.com/blog/html5-widget-api 中提供的示例并没有。所以我想知道,我在这里遗漏了什么,还是 API 有问题?这是我剥离的 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" type="text/javascript"></script>
<script>
$(document).ready(function() {
var widget = SC.Widget(document.getElementById('sc-widget'));
widget.bind(SC.Widget.Events.READY, ready());
function ready() {
widget.getDuration(function(durationSC) {
console.log('Duration: ' + durationSC);
});
}
$('button').click(function() {
widget.toggle();
});
});
</script>
</head>
<body>
<iframe id="sc-widget" src="http://w.soundcloud.com/player/?url=https://api.soundcloud.com/tracks/39804767&show_artwork=false&liking=false&sharing=false&auto_play=false" height="195" scrolling="no" width="480" frameborder="no"></iframe>
<button>Play / Pause</button>
</body>
</html>
【问题讨论】:
-
您正在调用
ready()而不是将其作为回调传递 –widget.bind(SC.Widget.Events.READY, ready);
标签: html widget soundcloud