I am creating a simple php page that plays back a video playlist using HTML5 video, and a jQuery bind function for fadeIn and play the next video after the current video ends.
Binding functions to a completed event works very well, but I would like to run the fadeIn and play function (say) 20 seconds before the video ends.
But I can’t figure out how to do this. Is it possible?
My HTML:
<video controls preload="auto"> <source src="sequence01.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' /> </video> <video controls preload="auto"> <source src="sequence01.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' /> </video>
My jQuery:
$('video').bind("ended", function(){ $(this).fadeOut(20000).next().fadeIn(20000).get(0).play(); });
SOLVE!
$('video').on('timeupdate', function(event) { var current = Math.round(event.target.currentTime * 1000); var total = Math.round(event.target.duration * 1000); if ( ( total - current ) < 20000 ) { $(this).fadeOut(2000).next().fadeIn(2000).get(0).play(); } });
Thank you so much for helping the guys, I was able to compose the answer using your wonderful comments, and this other seemingly inappropriate publication of SO:
Uncaught TypeError: Object [object Object] does not have a method of 'addEventlistner'
if anyone has a cleaner way to put this together, it will be awesome, but it seems to work very well for my purposes.
source share