1689 posts Envato Elite Author
  • Affiliate Level 2
  • Author Level 8
  • Collector Level 1
  • Top Monthly Author
+8 more
Tean
says

If I create a youtube iframe with jquery and append it to the dom like so:

var videoIFrame = $('<iframe>', {
frameborder: 0,
src: 'http://www.youtube.com/embed/u1zgFlCw8Aw?enablejsapi=1',
width: 400+'px',
height: 300+'px'
});</iframe>

I get a youtube video but how do I access youtube api from this?

5467 posts The Dude Abides
  • Top Monthly Author
  • Trendsetter
  • Weekly Top Seller
  • United States
+13 more
CodingJack
says

I’ve only used the jsapi once, but I think you have to add an id to the end of your src string like this:

http://www.youtube.com/e/VIDEO_ID?enablejsapi=1&version=3&playerapiid=ytplayer

Then catching the reference to the player:

function onYouTubePlayerReady(playerId)  {

      ytplayer = document.getElementById("myytplayer");

}

But the problem with this is that the video is loaded in an iframe and communicating becomes tricky. I haven’t tried this before but here’s a possible solution:

http://stackoverflow.com/questions/251420/invoking-javascript-in-iframe-from-parent-page
1689 posts Envato Elite Author
  • Affiliate Level 2
  • Author Level 8
  • Collector Level 1
  • Top Monthly Author
+8 more
Tean
says

Not sure why the syntax is so different from Vimeo iframe api.

For Vimeo after you create iframe the same way as above, you get the player reference like so:

vimeoPlayer = Froogaloop(videoIFrame[0]);

and thats it, you just listen for ‘ready’ event and you can use it.

But for youtube it goes like this:

http://apiblog.youtube.com/2011/01/introducing-javascript-player-api-for.html

I am not sure if this event onYouTubePlayerReady is going to be heard from jQuery.

5492 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Australia
  • Author Level 3
+5 more
Australia
says

Contact my mate nirvana tikku.

Via http://www.tikku.com/

He is a YouTube genius.

1689 posts Envato Elite Author
  • Affiliate Level 2
  • Author Level 8
  • Collector Level 1
  • Top Monthly Author
+8 more
Tean
says

Thanks, I saw this TubePlayer plugin before, but I wanted to use the simplest of embeds.

5492 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Australia
  • Author Level 3
+5 more
Australia
says
Tean said
Thanks, I saw this TubePlayer plugin before, but I wanted to use the simplest of embeds.

He is so helpful, just ask him.

by
by
by
by
by
by