There are two wrong function definitions in your code. On developer.mozilla.org you can find some very good javascript documentation. In particular, on this page, you can learn how to properly define functions: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions
Back to your code:
1) The getDuration
soundcloud function accepts a callback. function(sound)
is not a valid function definition.
2) A function definition does not need the var
keyword before the argument name
Here is your code with the two corrections. It works as you might expect.
var widget = SC.Widget(document.getElementById('playing'));
widget.bind(SC.Widget.Events.READY, function() {
console.log('Ready...');
});
$('button').click(function() {
widget.getDuration(function(duration){
alert(duration);
});
});
});
and here you can see the working fiddle: http://jsfiddle.net/Ldc2N/
One more thing: I see that in what was supposed to be the callback, you call document.write
.
function sound(time) { document.write(time); }
Please consider that it only appends content to the document when it is not ready, yet. Calling int when the document is ready completely overwrites its content.