javascript - soundcloud 嵌入中的时间和事件

标签 javascript php dom-events soundcloud

如何使用 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

关于javascript - soundcloud 嵌入中的时间和事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29259169/

相关文章:

javascript - 根据 JavaScript 中的屏幕大小删除其他元素

PHP If 语句混淆

javascript - touchmove 什么时候真正触发?

php - 如何在不使用文本字段的情况下将哈希存储在 MySQL 数据库中

javascript - 检查复选框和单选按钮是否被选中

javascript - 防止浏览器在 HTML5 History popstate 上滚动

javascript - String::toByteArray() 无法在 Kotlin [js] 中编译

javascript - JS Code over AJAX with jQuery - 这种方法安全吗?

javascript - 使用复选框+标签组合防止双击错误

php - 使用ckeditor在网页上显示图像,在图像源中添加额外的双引号和斜杠