How to add Event Listener for Event after Youtube video is finished playing
I am trying to get an event fired once the youtube video reached its end.
The video embedding works, but nothing happens once the video ends. I
think I am missing something for the EventListener...
this is my code:
var params = { allowScriptAccess: "always" };
var atts = { id: "myytplayer" };
var video =
swfobject.embedSWF("http://www.youtube.com/v/elvOZm0d4H0?enablejsapi=1&playerapiid=ytplayer&version=3&rel=0&autoplay=1&controls=1","ytapiplayer",
"450", "250", "8", null, null, params, atts);
XXXXX.addEventListener("onStateChange", function(state){
if(state === 0){
alert("Stack Overflow rocks!");
}
});
What I do not get is, what I should listen to? Marked with "XXXXX" in the
code, what do i need to put there? I tried myytplayer, video, ytplayer,
ytapiplayer... most of them give me an error, e.g. "ytplayer can not be
found". "ytapiplayer" did not throw an error, but also nothing happens
once the video is finished playing.
I searched stack Overflow, but all the "answers" I found so far are just
naming this event listener, but do not explain what I have to put at
"XXXXX".
I am pretty new to this and any help is very welcome, thanks!
JSFIDDLE: http://jsfiddle.net/T5HBZ/
edit: edited code for controls, added jsfiddle
No comments:
Post a Comment