soundcloud 中的时间和事件嵌入

Time and events in soundcloud embed

如何在 JavaScript 或 PHP 中获取 SoundCloud 上曲目的持续时间?我可以将此持续时间用于 JavaScript 个事件吗?

工作 JSFiddle:https://jsfiddle.net/aj3Pw/1/

HTML:

<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F7659975" id="player"></iframe>

<button id="play">Play</button>

JS:

var iframe = document.querySelector('#player');
var sc = SC.Widget(iframe);

sc.bind(SC.Widget.Events.READY, function() {
    var d = document.createTextNode('Ready');
    document.querySelector('body').appendChild(d);
});

document.querySelector('button').addEventListener('click', function() {
    sc.play();
    sc.getDuration(function(duration) {
            console.log(duration);
            // do whatever you need to with the duration variable
        });
});

相关文档:https://developers.soundcloud.com/docs/widget#methods