我正在努力使用 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>