This is a question similar to how to pass arguments to addeventlistner But the scenario is a bit different by using Youtube player's api.
So I have multiple youtube player on the 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 to generate the ytplayer object id. And I'm listening the event onStateChange in another function.
ytplayer.addEventListener("onStateChange", "onytplayerStateChanged");
function onytplayerStateChanged(newState) {
if(newState == -1){
//unstarted
}else{
debugger;
}
}
But the problem is I cannot know which ytPlayer this event comes from. (find the source of the caller in the onytplayerStateChanged function) Since I'm only able to catch this event by following the exact implementation of this structure. I tried the implementation on This one but it won't catch the event anymore.