Skip to content

Instantly share code, notes, and snippets.

@AramZS
Last active September 2, 2015 08:22
Show Gist options
  • Save AramZS/5eaa45c310d45865ffce to your computer and use it in GitHub Desktop.
Save AramZS/5eaa45c310d45865ffce to your computer and use it in GitHub Desktop.
Brightcove
<!-- Start of Brightcove Player -->
<div style="display:none">
</div>
<div id="thePlayer">
<!--
By use of this code snippet, I agree to the Brightcove Publisher T and C
found at https://accounts.brightcove.com/en/terms-and-conditions/.
-->
<script type="text/javascript" src="http://admin.brightcove.com/js/BrightcoveExperiences.js"></script>
<script type="text/javascript" src="http://admin.brightcove.com/js/api/SmartPlayerAPI.js"></script>
<object id="myExperience3836448777001" class="BrightcoveExperience">
<param name="bgcolor" value="#FFFFFF" />
<param name="width" value="486" />
<param name="height" value="412" />
<param name="playerID" value="3830484134001" />
<param name="playerKey" value="AQ~~,AAABrRrr8AE~,mpZPdzFWzuGiL7-LQS3_Qw7YI7SIayhX" />
<param name="isVid" value="true" />
<param name="dynamicStreaming" value="true" />
<param name="@videoPlayer" value="3836448777001" />
<!-- smart player api params -->
<param name="includeAPI" value="true" />
<param name="templateLoadHandler" value="onTemplateLoad" />
<param name="templateReadyHandler" value="onTemplateReady" />>
</object>
<!--
This script tag will cause the Brightcove Players defined above it to be created as soon
as the line is read by the browser. If you wish to have the player instantiated only after
the rest of the HTML is processed and the page load is complete, remove the line.
-->
<script src="//docs.brightcove.com/en/scripts/https-fix.js"></script>
<script type="text/javascript">brightcove.createExperiences();</script>
<!-- End of Brightcove Player -->
</div>
<script type="text/javascript">
var player,
APIModules,
videoPlayer;
function isScrolledIntoView(elem){
var docViewTop = jQuery(window).scrollTop();
var docViewBottom = docViewTop + jQuery(window).height();
var elemTop = jQuery(elem).offset().top;
var elemBottom = elemTop + jQuery(elem).height();
return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom)
&& (elemBottom <= docViewBottom) && (elemTop >= docViewTop) );
}
function onTemplateLoad(experienceID){
player = brightcove.api.getExperience(experienceID);
APIModules = brightcove.api.modules.APIModules;
}
function checkIfVideoInView(){
if ( isScrolledIntoView(thePlayer) ) {
videoPlayer.mute();
videoPlayer.play();
}
}
function onTemplateReady(evt){
videoPlayer = player.getModule(APIModules.VIDEO_PLAYER);
checkIfVideoInView(thePlayer);
}
window.onscroll = checkIfVideoInView;
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment