Ronan Jouchet
Ronan Jouchet

Reputation: 1333

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!

Upvotes: 2

Views: 3236

Answers (2)

SteeleMage
SteeleMage

Reputation: 1

You might also try checking the value being passed for the "origin" query string parameter.

I was getting a similar error that was puzzling me for awhile, then realized I was passing the "&origin=http://example.com" parameter in the query string parameters, but was in my test environment that has a different host/domain name than the production code. Once I changed it so it sent the proper origin, I was able to work with the video/player without getting the "getPlayerState" error.

Upvotes: 0

DCrystal
DCrystal

Reputation: 721

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="

Upvotes: 3

Related Questions