2012-05-01 27 views
1

我使用的是SC HTML5播放器,當一個聲音結束時,我加載另一個聲源,但是FINISH事件似乎只對第一首歌曲發聲,我的代碼是如下Soundcloud HTML5 Player:Events.FINISH只發射一次

//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目標設置爲另一個函數,但那不起作用,我錯過了什麼?謝謝!

回答

2

我有同樣的問題。當我第一次調用它時,SC.Widget方法工作正常,但如果我第二次嘗試調用它,控制檯將在http://w.soundcloud.com/player/api.js腳本中觸發「Uncaught TypeError:無法讀取屬性'parentWindow'null」錯誤。這就是api.js腳本停止的動作(.Widget,.bind等)

我找到了解決方案。這很奇怪,但它是一個解決方案。 SoundCloud遠程腳本被縮小。將它加載到瀏覽器中,在一些在線美化器中進行C/P並將其保存在本地。編輯第103行如下:

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

所以我刪除了.parentWindow調用。

保存該文件並將其稱爲您的頁面頭部分。就是這樣!現在FINISH事件在每個加載的小部件上觸發。

我希望這會有所幫助。

+0

截至2012年10月10日,soundcloud api.js的最終結果如下:http://pastebin.com/S13JxRw3 – Autonomy