1675 posts Envato Elite Author
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Author had a Free File of the Month
  • Exclusive Author
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Europe
  • Has been a member for 4-5 years
  • Referred between 10 and 49 users
+1 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?

5277 posts The Dude Abides
  • United States
  • Exclusive Author
  • Has been a member for 5-6 years
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Bought between 100 and 499 items
  • Referred between 100 and 199 users
+5 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
1675 posts Envato Elite Author
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Author had a Free File of the Month
  • Exclusive Author
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Europe
  • Has been a member for 4-5 years
  • Referred between 10 and 49 users
+1 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.

5075 posts
  • Australia
  • Bought between 100 and 499 items
  • Community Superstar
  • Exclusive Author
  • Has been a member for 3-4 years
  • Interviewed on the Envato Notes blog
  • Microlancer Beta Tester
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
Australia says

Contact my mate nirvana tikku.

Via http://www.tikku.com/

He is a YouTube genius.

1675 posts Envato Elite Author
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Author had a Free File of the Month
  • Exclusive Author
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Europe
  • Has been a member for 4-5 years
  • Referred between 10 and 49 users
+1 more
Tean says

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

5075 posts
  • Australia
  • Bought between 100 and 499 items
  • Community Superstar
  • Exclusive Author
  • Has been a member for 3-4 years
  • Interviewed on the Envato Notes blog
  • Microlancer Beta Tester
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
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