javascript - How to use an iframe as input for YT.Player -


the docs should use div container <iframe> element appended.

that works:

new yt.player('player', {    height: '390',    width: '640',    videoid: 'm7lc1uvf-ve',    events: {       onready: onplayerready,       onstatechange: onplayerstatechange    } }); 

but should have element <div id="player"></div> on page.

is possible if have iframe element embedded video use iframe in yt.player constructor?

i have this:

new yt.player('iframeid').playvideo(); 

but playvideo isn't there because player not loading (i guess that's happening because providing iframe id).

is there way connect existing iframe yt.player instance?

i wrote quick hack it: get video id <iframe> url, replace iframe div , initialize player:

ytplayeriframe = (function () {   function youtube_parser(url){      var regexp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;      var match = url.match(regexp);      return (match&&match[7].length==11)? match[7] : false;   }   var __oldplayer = yt.player;   var player = function (id, options) {     var el = document.getelementbyid(id);     options.videoid = youtube_parser(el.getattribute("src"))     el.outerhtml = "<div id='" + id + "'>test</div>";     return new __oldplayer(id, options);   };   return player; })(); 

then can use way:

var myplayer = ytplayeriframe("iframe-id", {    // videoid option taken iframe src.    events: {       onready: function () {...}    } }); 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -