问题
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