PetroFrolov / vast-video-js

VAST-Ad plugin for HTML5 by video.js
79 stars 33 forks source link

Event for when all videos finished playing. #19

Open dmoath opened 11 years ago

dmoath commented 11 years ago

Hi, first of all, thanks for this awesome plug-in!, i was wondering if you could create an event for when all videos finished playing (Ad+main video), i'm putting everything in an iframe that shows in a jQuery lightbox, so only when all the videos end playing i want to close the lightbox, currently, i'm listening for the "ended" event and closing but that closes the lightbox right after the first video (ad) ends.

blueone1 commented 11 years ago

I'm also interested in this. Any solution?

PetroFrolov commented 11 years ago

I think that you can listen both 'play' and 'ended' and do like that... onplay: if (is_ended && f) { clearTimeout(f); f = 0;} onended: is_ended=true; f=setTimeout(some_close_func, 1000);

blueone1 commented 11 years ago

Hi Petro,

Thank you for your reply! Could you (or someone) perhaps expand on your code to someone who is a beginner in Javascript? I am not sure how to get that working properly and what the "f" variable refers to or how it would look when it is actually applied in the code .. (example what some_close_func) might be. I was looking more at code like this:

var myFunc = function(){ window.location.href = "http://google.com" }; myPlayer.addEvent("ended", myFunc);

How would yours fit in there?

PetroFrolov commented 11 years ago

var myFunc = function(){ window.location.href = "http://google.com" };

var onPlay = function() { if (window.myTimer && window.isEnded) { clearTimeout(window.myTimer); window.isEnded = false; } };

var onEnded = function() { window.isEnded = true; window.myTimer = setTimeout(myFunc, 1000);//call myFunc after 1s };

myPlayer.addEvent("play", onPlay); myPlayer.addEvent("ended", onEnded);

blueone1 commented 11 years ago

Thank you, Petro!