javascript - How to get the source or id from youtube player onstatechange callback -
this question similar how pass arguments addeventlistner scenario bit different using youtube player's api.
so have multiple youtube player on same page, using swfobject:
swfobject.embedswf("http://www.youtube.com/v/"+video_id+"?enablejsapi=1&version=3&modestbranding=1&theme=light&color=white&autohide=1&controls=1&showinfo=0&iv_load_policy=3&autoplay=0&playerapiid=<%= "ytplayer#{index}" %>", "<%= "ytplayer#{index}" %>", "500", "280", "8", null, null, params);
where i'm using ruby generate ytplayer object id. , i'm listening event onstatechange in function.
ytplayer.addeventlistener("onstatechange", "onytplayerstatechanged"); function onytplayerstatechanged(newstate) { if(newstate == -1){ //unstarted }else{ debugger; } }
but problem cannot know ytplayer event comes from. (find source of caller in onytplayerstatechanged function) since i'm able catch event following exact implementation of structure. tried implementation on this one won't catch event anymore.
i think can embed id , add listener dynamic function propose here: how display multiple youtube videos without overlapping audio
window["dynamicyoutubeeventhandler" + embedid] = function(state) { onytplayerstatechange(state, embedid); } ytplayer.addeventlistener("onstatechange", "dynamicyoutubeeventhandler"+embedid); (...) function onytplayerstatechange(newstate, playerid)
Comments
Post a Comment