Play event not firing on start on HTML5 widget

泪湿孤枕 提交于 2019-12-08 03:53:11

问题


When SoundCloud HTML5 Player Widget is loaded with autoplay option, play event not firing when track starts. However there is a timeout between loading the widget (or loading other URL into the widget) and when the track starts, so it's nice widget to call the event.

Is this by design or is it issue to be solved?


回答1:


The HTML5 Player widget should fire a SC.Widget.Events.PLAY event when the auto_play option is used. Here's a code snippet I used to verify:

HTML:

<!doctype html>
<html>
  <head>
    <title>Widget Demo</title>
    <style type="text/css">
    iframe {
      display:block;
      border:0;
      margin-bottom: 20px;
      height: 365px;
    }
    </style>
  </head>
  <body>
    <iframe id="widget" width="100%"></iframe>
  </body>
  <script src="http://w.soundcloud.com/player/api.js"></script>
  <script src="script.js"></script>
</html>

JavaScript (the contents of script.js):

(function() {
    var iframe = document.querySelector('#widget');
    iframe.src = 'http://w.soundcloud.com/player/?url=http://api.soundcloud.com/tracks/43315398&auto_play=true';

    var widget = SC.Widget(iframe);

    widget.bind(SC.Widget.Events.PLAY, function(eventData) {
        alert('Playing...');
    });
}());

You can check out a working example here on jsfiddle.



来源:https://stackoverflow.com/questions/10288253/play-event-not-firing-on-start-on-html5-widget

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!