相当难住了这一点。JQuery的/的Youtube API - 在模拟DOM太多的递归调用错误点击
我使用YouTube JS API,以确定一首歌曲已经结束。当它结束时,我想调用播放下一首歌曲的方法。
这里是我的事件监听器方法(CoffeeScript的):
window.statechange = (newstate) ->
debug = true
if debug then console.log 'Player State Change: ' + newState
switch newState
when 0 #song ended
if debug then console.log 'Song Ended'
when 1 #song is playing
if debug then console.log 'Song Playing'
#change the title of the page
document.title = $('#currentSongTitle').html() + ' by ' +
$('#currentSongArtist').html()
when 2 #song is paused
if debug then console.log 'Song Paused'
when 3 #song is buffering
if debug then console.log 'Song Loading'
的方法正常工作以这种形式。当歌曲结束,Firebug的控制台显示Song Ended
然而,当我修改代码以添加一个模拟点击,将触发下一首歌曲的功能,它给了我一个too much recursion
错误和崩溃:
when 0 #song ended
if debug then console.log 'Song Ended'
$('.next-song').click()
这里是下一首歌点击时的代码:
就是这样。在它崩溃之前,控制台会说'下一首歌曲被点击',但之后它会崩溃,并给出太多的递归错误。一条线如何导致任何递归?
更加混乱的是,以下方法适用于没有错误。
$(document).on 'click', '#debug-next-song', ->
$('.next-song').click()
编辑:我与确保模拟点击作品的目的,创造了它找出了一切工作正常在Chrome,但在Firefox完全崩溃。你可以在(http://t3k.no/beta)看到错误。在当前歌曲的右侧,单击“下一步”可以正常工作。但是,如果你开始播放歌曲在屏幕的底部,等待它结束,代码$('.next-song').click()
被称为和崩溃的Firefox。
点击可能触发另一个'window.statechange'调用。你有没有在任何地方玩的例子? – 2012-02-12 22:37:38
这就是我一开始以为过,但它没有任何意义,我认为这会触发该方法。如果是,控制台应该记录'if debug then console.log'Player State Change:'+ newState'如果状态发生变化。 我上传的破碎版本到我的网站在这里:http://t3k.no/beta(注意,它崩溃我的Firefox当歌曲结束) – CHawk 2012-02-13 02:45:10
更加古怪:现在,我上传到我的网站,我发现它在Chrome但崩溃的Firefox ... – CHawk 2012-02-13 02:47:31