YouTube API onPlayerReady not firing

后端 未结 3 1216
鱼传尺愫
鱼传尺愫 2020-12-09 09:26

I created a new page especially to test the API. When copy pasting their example with

and

         


        
相关标签:
3条回答
  • 2020-12-09 09:58

    Per issue 5670:

    A quick fix is to add in the origin=http://www.example.com (replace with your servers full domain; make sure you use http:// or https:// as appropriate for your site) to the src= attribute of the player's iframe element. Please make sure that the origin= attribute's value exactly matches the host domain and URL scheme. E.g.

    <iframe
      type="text/html"
      width="640"
      height="480"
      src="https://www.youtube.com/embed/VIDEO_ID?enablejsapi=1&origin=https://www.example.com"
      frameborder="0">
    </iframe>
    
    0 讨论(0)
  • 2020-12-09 10:04

    Also experienced this issue in one of our apps earlier today, I believe it's as a result of some internal changes / code push in youtube. Something similar happened in June c.f YouTube iframe player API - OnStateChange not firing

    I resolved my issue by replacing

    <iframe id="ytplayer" ... src="http://www.youtube.com/embed/wQ78D6zoVKo"></iframe>
    

    with

    <div id="ytplayer"></div>
    

    thus letting the js script replace the div.

    The clue was in your questions, so thanks.

    0 讨论(0)
  • 2020-12-09 10:07

    A fix was finally posted: https://code.google.com/p/gdata-issues/issues/detail?id=5670#c6

    Here is a direct quote of the answer at the link above:

    A quick fix is to add in the origin=http://www.example.com (replace with your servers full domain; make sure you use http:// or https:// as appropriate for your site) to the src= attribute of the player's iframe element. Please make sure that the origin= attribute's value exactly matches the host domain and URL scheme. E.g.

    <iframe
      type="text/html"
      width="640"
      height="480"
      src="https://www.youtube.com/embed/VIDEO_ID?enablejsapi=1&origin=https://www.example.com"
      frameborder="0">
    </iframe>
    

    I'm currently working with the engineering team to figure out whether origin= is going to be required moving forward or whether this new requirement can be reverted, but this is the immediate fix. Apologies for the breakage and lack of advanced communication in the meantime.

    If you use the YT.Player() constructor to create the iframe element for you then this isn't be an issue—it's a bit of an edge case for developers who are explicitly including the iframe element as part of their page's HTML.

    I implemented the fix above, and it worked for me.

    0 讨论(0)
提交回复
热议问题