我試圖寫一個腳本,一旦按下按鈕,它就會顯示SoundCloud中歌曲的持續時間。我也對這些API有點麻煩。我已閱讀並重讀關於某個「回調」的行傳遞了一個參數,但我仍然不明白。 「因此,每個getter方法都會接受一個回調函數作爲參數,當被調用時,它將被賦予getter方法的返回值。」SoundCloud Getters - getDuration
這裏是我在我的代碼。我知道它不漂亮,但我只是想讓這件事情起作用。
<!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>
啊好吧。真棒!非常感謝! – user3316362
不客氣。如果你發現答案有用,請考慮投票(這就是stackoverflow的工作方式;-))。謝謝。 –
我會如何去做這個沒有按鈕?只要頁面加載彈出窗口顯示出來? – user3316362