1

My iframe html

<iframe id="player" frameborder="0" width="660" height="371" allowfullscreen="" src="https://www.youtube.com/embed/CMm6tDavSXg?feature=oembed">

My youtube js

  var tag = document.createElement('script');

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

var player;
function onYouTubeIframeAPIReady() {
  player = new YT.Player('player', {
    events: {
 'onReady': onPlayerReady,
      'onStateChange': onPlayerStateChange
    }
  });
}
function onPlayerReady(event) {
        event.target.playVideo();
      }

But still it does not start playing or anything else... Where is the issue here? Thank you

Marc Ster
  • 2,276
  • 6
  • 33
  • 63
  • it's working like a charm http://jsbin.com/cucebugico/1/edit?html,js,output the problem is somewhere else – mpgn Oct 19 '14 at 12:28
  • hm it does not work for me with jsbin oder jsfiddle either? Shouldn't it start playing when ready? – Marc Ster Oct 20 '14 at 07:11

1 Answers1

1
  • onPlayerReady will not fire the ready check on localhost.
  • Also when linking your youtube.js file it has to come after the iframe.
  • add ?enablejsapi=1
  • sometimes double linking in both player_api and iframe_api will also help
  • //< before www. not https://
  • placment is key.

EDIT: the problem is with the fact that you also need to add ?enablejsapi=1 to the video embed link.

//www.youtube.com/embed/F4efZDqXZKA?enablejsapi=1

fiddle: http://jsfiddle.net/y89je0k8/

That will solve your problem.

EVX
  • 304
  • 4
  • 17