javascriptiframeyoutubeyoutube-apiyoutube-javascript-api

player.getPlayerState is unavailable after YouTube Iframe API initialization


A feature using the YouTube Iframe API has been broken for a while on a little music discovery site I have, and I'm trying to understand why:

  1. Open www.dailygrooves.org
  2. Press the spacebar key.

→ Expected: playback should start.

→ Actual: the playpause function throws TypeError: player.getPlayerState is not a function when running var playerState = player.getPlayerState(). And looking at my player object, indeed this method is missing:

    screenshot of the 'player' object in my DevTools

What's wrong in my API usage / initialization? It used to work fine, and I think started to fail a few months ago, even though the YouTube Iframe Player API Reference mentions no recent changes to the API. Thanks for the help!


Solution

  • Add

    enablejsapi=1
    

    to the iframe 'src' attribute. E.g.:

    http://www.youtube.com/embed/videoseries?wmode=opaque&autohide=0&disablekb=1&enablejsapi=1&list="