Soundcloud HTML5播放器:Events.FINISH只触发一次 [英] Soundcloud HTML5 Player: Events.FINISH only fired once

查看:101
本文介绍了Soundcloud HTML5播放器:Events.FINISH只触发一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SC HTML5播放器,当一个声音结束时,我加载到另一个声源,但是FINISH事件似乎只为第一首歌开始,我的代码如下:

I'm using the SC HTML5 player, when one sound finishes, I load in another source, however the FINISH event only seems to fire for the first song, my code is as follows

//Set the source
document.getElementById("sc-widget").src = scPath;
//get the widget reference
var widgetIframe = document.getElementById('sc-widget'),
widget       = SC.Widget(widgetIframe);
//set the finish event
widget.bind(SC.Widget.Events.FINISH, endSC);

function endSC() {
                    var scPath = "http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F1848538&show_artwork=true&auto_play=true";
                    document.getElementById("sc-widget").src = scPath;
                    var widgetIframe = document.getElementById('sc-widget'),
                    widget       = SC.Widget(widgetIframe);
                    widget.bind(SC.Widget.Events.FINISH, endSC);
}

我尝试将endSC目标设置为另一个函数但不是工作,我错过了什么?谢谢!

I've tried setting the endSC target to another function but that doesn't work, what am I missing? Thanks!

推荐答案

我遇到了同样的问题。当我第一次调用它时,SC.Widget方法正常工作,但如果我第二次尝试调用它,控制台将触发未捕获的TypeError:无法读取属性'parentWindow'的null错误 http://w.soundcloud.com/player/api.js 脚本。这就是api.js脚本停止的动作(.Widget,.bind等)。

I had the same problem. SC.Widget method is working fine when I call it for the first time, but if I try to call it for the second time the console will fire "Uncaught TypeError: Cannot read property 'parentWindow' of null" error in http://w.soundcloud.com/player/api.js script. And that is where api.js script stops with actions (.Widget, .bind, etc.)

我找到了解决方案。这很奇怪,但这是一个解决方案。
SoundCloud远程脚本被缩小。将它加载到您的浏览器中,在某些在线js中进行C / P美化并在本地保存。编辑第103行,如下所示:

I found the solution. It's very weird, but it is a solution. SoundCloud remote script is minified. Load it in your browser, C/P it in some online js beautifier and save it locally. Edit line 103 as follows:

return a.contentWindow;// || a.contentDocument.parentWindow

所以我删除了.parentWindow电话。

So I removed that .parentWindow call.

保存文件并在页面的主题部分中调用它。就是这样!现在FINISH事件会在每个加载的小部件上触发。

Save the file and call it in your page's head section. And that's it! Now FINISH event fires on every loaded widget.

我希望这会有所帮助。

这篇关于Soundcloud HTML5播放器:Events.FINISH只触发一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆