Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7498403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:27:57+00:00 2026-05-29T19:27:57+00:00

Quite stumped on this one. I am using the Youtube JS API to determine

  • 0

Quite stumped on this one.

I am using the Youtube JS API to determine when a song has ended. When it is ended, I want to call a method that plays the next song.

Here is my event listener method (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'

The method works correctly in this form. When the song ends, FireBug’s console displays Song Ended

However, when I modify the code to add a simulated click that would trigger the next song function, it gives me a too much recursion error and crashes:

when 0 #song ended
        if debug then console.log 'Song Ended'
        $('.next-song').click()

Here is the code for when next-song is clicked:

$(document).on 'click', '.next-song', ->
    console.log 'Next-song clicked'

That’s it. Before it crashes, the console DOES say ‘Next-song clicked’, but then it crashes and gives the too much recursion error. How could a 1 line cause any recursion at all?

Even more confusing is that the following method works with no errors. I created it with the purpose of making sure the simulated click works:

$(document).on 'click', '#debug-next-song', ->
    $('.next-song').click()

EDIT: Found out everything works fine in Chrome but completely crashes in Firefox. You can see the error first hand at (http://t3k.no/beta). On the right where it says current song, clicking ‘Next’ works fine. But if you start playing the song at the bottom of the screen and wait for it to end, the code $('.next-song').click() is called and crashes Firefox.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T19:27:59+00:00Added an answer on May 29, 2026 at 7:27 pm

    I’m not really sure why this is happening, but going through the source on your site I noticed you’re actually triggering the click in a return. I don’t see why this wouldn’t work, but if you separate those into two statements, it seems to work for me.

    change:

    switch (newState) {
          case 0:
            if (debug) console.log('Song Ended');
            return $('.next-song').click();
    // ...
    

    to:

    switch (newState) {
          case 0:
            if (debug) console.log('Song Ended');
            $('.next-song').click();
            return; 
    // ...
    

    Since you’re using CoffeeScript, you can use the return keyword explicitly.

    when 0 #song ended
        if debug then console.log 'Song Ended'
        $('.next-song').click()
        return
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This has me stumped. This is quite a simplified version but let's say I
I'm quite confused by this one. I've build a read more button using mostly
Quite often one has to encode an big (e.g. 128 or 160 bits) number
Ok, I'm quite stumped here. I'm getting an error, eclipse/android is saying that my
I'd like to find out which processes are using my network. This is quite
I'm quite stumped on this issue. I have a large library of H.264 mp4
I am quite stumped with this. In enhancing an existing feature to a SharePoint
I have quite a bit of experience with css and even this problem has
I have to admit I am COMPLETELY stumped on this one. I've been scouring
Okay, I'm a little stumped with this one. I am usng Cufon to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.