Yet more Fun w/Jwplayer & ad calls & events
Now w/our own ads
by deanpeters
HTML
<script src="http://jwpsrv.com/library/0IAkvmXBEeSJ2xLddj37mA.js"></script>
<script>jwplayer.key="EGMgYLlqVmdDY5kcRZDEuYOfWEzvirXZ/PrR0xJaoejzFfKOtLzBZQ==";</script>
<h1>JWPlayer 6</h1>
<div id="container" class="jwplayer playlist-none"> </div>
<div id="container_jwpsrv"> </div>
CSS
#container {
position: relative;
padding-bottom: 56%;
padding-top: 20px;
height: 0;
}
div.jwpreview.jwexactfit {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
JavaScript
$('head').append('<meta name="viewport" content="width=device-width, initial-scale=1" />');
$('head').append('<meta content="authenticity_token" name="csrf-param" />');
$('head').append('<meta content="EGMgYLlqVmdDY5kcRZDEuYOfWEzvirXZ/PrR0xJaoejzFfKOtLzBZQ==" name="csrf-token" />');
$('container').append(' <input type="hidden" name="authenticity_token" value="EGMgYLlqVmdDY5kcRZDEuYOfWEzvirXZ/PrR0xJaoejzFfKOtLzBZQ==" />');
var jwp = jwplayer("container").setup({
file: 'http://www.youtube.com/watch?v=IjScvb5hiw0',
image: '//i.ytimg.com/vi/IjScvb5hiw0/mqdefault.jpg',
stretching: 'exactfit',
aspectratio: '4:3',
width: '100%',
fallback: 'true',
primary: 'HTML5',
advertising: {
client: 'googleima',
tag: 'http://pubads.g.doubleclick.net/gampad/ads?sz=400x300&iu=/7675/MCI.site_escenic-prod&ciu_szs&impl=s&gdfp_req=1&env=vp&output=xml_vast2&unviewed_position_start=1&url=[referrer_url]&hl=en&cust_params=pos%3D2&correlator=[timestamp]'
}
});
var playonce = false;
jwp.onBeforePlay(function () {
if (!playonce) {
// window.alert("This is where we can force an ad call");
console.log("onBeforePlay event fired, pre-playAd()");
jwplayer("container").playAd("http://pubads.g.doubleclick.net/gampad/ads?sz=400x300&iu=/7675/MCI.site_escenic-prod&ciu_szs&impl=s&gdfp_req=1&env=vp&output=xml_vast2&unviewed_position_start=1&url=[referrer_url]&hl=en&cust_params=pos%3D2&correlator=[timestamp]");
console.log("onBeforePlay event fired, post-playAd()");
};
playonce = true;
});
jwp.onAdImpression(function (event) {
console.log("The ad impression was fired.");
});
jwp.onAdTime(function (event) {
var remaining = Math.round(event.duration - event.position);
console.log("The ad completes in " + remaining + " seconds.");
});
jwp.onAdClick(function (event) {
console.log("The user clicked the ad.");
});
jwp.onAdComplete(function (event) {
console.log("The ad was completely...