如何使用 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
});
});
关于javascript - soundcloud 嵌入中的时间和事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29259169/