Matt Law
Matt Law

Reputation: 73

youtube api , firefox 4.0 . iframe failing to load videos

Trying to fix this issue with iFrame and Firefox 4.0 failing to load videos This is currently my code. I have tried to look into this site - https://developer.mozilla.org/en/HTML/HTML5/Optimizing_Your_Pages_for_Speculative_Parsing for assistance. But It doesn't quite make much sense to me.

Any assistance would be grateful

Regards Matt

<div id="myVid"></div>

        <script>

          var tag = document.createElement('script');
          tag.src = "http://www.youtube.com/player_api";
          var firstScriptTag = document.getElementsByTagName('script')[0];
          firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);


          var player;
          function onYouTubePlayerAPIReady() {
            player = new YT.Player('myVid', {
              height: '80%',
              width: '100%',
              events: {
                'onReady': onPlayerReady,
                'onStateChange': onPlayerStateChange
              }
            });
          }


          function onPlayerReady(event) {
            event.target.playVideo();
          }



          function onPlayerStateChange(event) {
            if (event.data == YT.PlayerState.ENDED) {
              getVideo();

            }
          }

        </script><

Upvotes: 0

Views: 643

Answers (1)

arttronics
arttronics

Reputation: 9955

Using the YouTube Embed Method requires modern browsers with HTML5 postMessage support.

The version of Firefox you are using is version 4.0 but postMessage is available in Firefox starting from version 6.

YouTube API Embed Requirements:
https://developers.google.com/youtube/iframe_api_reference#Requirements

HTML5 postMessage Reference:
https://developer.mozilla.org/en/DOM/window.postMessage

Coincidentally, if you were using Firefox Version 6 and your embed markup was complete with Video ID, you will be subject to a catastrophic bug that's surfaced the last two days for the YouTube Embed API... Flash Fallback is broken! See this SO workaround solution if applicable to you:
https://stackoverflow.com/a/10560802/1195891

Upvotes: 1

Related Questions