Is there any known way of auto playing video when video is in viewport, I use the following function to determine when an element is in viewport
var isScrolledIntoView = function(elem) {
// get the position of the viewport
var docViewTop = $(window).scrollTop();
var docViewBottom = docViewTop + $(window).height();
// get the position of the player element
var elemTop = $(elem).offset().top;
var elemBottom = elemTop + $(elem).height();
// determine if the player element is in fully in the viewport
return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom)
&& (elemBottom <= docViewBottom) && (elemTop >= docViewTop) );
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//releases.flowplayer.org/6.0.5/flowplayer.min.js"></script>
<link rel="stylesheet" href="//releases.flowplayer.org/6.0.5/skin/functional.css">
<div class="flowplayer" data-swf="http://releases.flowplayer.org/6.0.5/commercial/flowplayer.swf">
<video>
<source type="video/mp4" src="http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4">
</video>
</div>
I tried few samples as explained at https://flowplayer.org/docs/api.html and it doesn't seems to be working for me
You can use
flowplayer(0).play()
in order to play the view.As for "when it's in view" - you can check here.
Update
Added a variable to check if we already played the video to make sure we don't play it twice (after the user paused it or the video ended already).
I made small modifications to previous answer. Now this code loops all flowplayer clases on same page. Every video on page starts automatic. I added pause event too, so there should be only one video at the time playing if not located side by side on page.