时间和事件嵌入声云

Time and events in soundcloud embed

本文关键字:事件 时间      更新时间:2023-09-26

如何在SoundCloud上用JavaScript或PHP获取曲目的持续时间?我可以将此持续时间用于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