A Copy of the code is here, I couldn't attach it as a file.
// Add a hidden id="googleLang" with the possible languages
var googleLanguage = 'en';
if($('#googleLang'))
{
googleLanguage = $('#googleLang').html();
if(googleLanguage === '' || googleLanguage === undefined) googleLanguage = 'en';
}
var adsRequested = false;
// Copyright 2013 Google Inc. All Rights Reserved.
// You may study, modify, and use this example for any purpose.
// Note that this example is provided "as is", WITHOUT WARRANTY
// of any kind either expressed or implied.
/**
* Handles user interaction and creates the player and ads controllers.
*/
var Application = function() {
this.adTagBox_ = document.getElementById('tagText');
this.sampleAdTag_ = document.getElementById('sampleAdTag');
// Match was crashing because this element didn't exist
if(!this.sampleAdTag_)
{
return;
}
this.sampleAdTag_.addEventListener(
'click',
this.bind_(this, this.onSampleAdTagClick_),
false);
this.console_ = document.getElementById('console');
this.playButton_ = document.getElementById('playpause');
this.playButton_.addEventListener(
'click',
this.bind_(this, this.onClick_),
false);
this.fullscreenButton_ = document.getElementById('fullscreen');
this.fullscreenButton_.addEventListener(
'click',
this.bind_(this, this.onFullscreenClick_),
false);
this.fullscreenWidth = null;
this.fullscreenHeight = null;
var fullScreenEvents = [
'fullscreenchange',
'mozfullscreenchange',
'webkitfullscreenchange'];
for (key in fullScreenEvents) {
document.addEventListener(
fullScreenEvents[key],
this.bind_(this, this.onFullscreenChange_),
false);
}
this.playing_ = false;
this.adsActive_ = false;
this.adsDone_ = false;
this.fullscreen = false;
this.videoPlayer_ = new VideoPlayer();
this.ads_ = new Ads(this, this.videoPlayer_);
this.videoPlayer_.registerVideoEndedCallback(
this.bind_(this, this.onContentEnded_));
};
// &slotname=9617174290 = Multiplayer Video Desktop, TrueView & Instream up to 15 seconds
Application.prototype.log = function(message) {
//console.log(message);
this.console_.innerHTML = this.console_.innerHTML + '<br/>' + message;
};
Application.prototype.resumeAfterAd = function() {
$('#videocontainer').hide();
$('#MatchCommentaryScreen').show();
$('#quickLinks').show();
$('nav .container').show(); // Show top nav content
$('aside div').show(); // Show left menu content
$('aside ul').show(); // Show left menu content
$('aside .sub-menu ul').css('display', 'none'); // Collapse all Left menu items
$('#leftAd').show();
$('#footer').show();
// Old UI
$('#liveMatchContent').show();
$('#adslot_1').show();
$('#adslot_1').css('visibility', 'visible');
$('#adslot_top').show();
// Old UI
$('#liveMatchContent').show();
$('#adslot_1').show();
$('#adslot_1').css('visibility', 'visible');
$('#adslot_top').show();
//this.videoPlayer_.play();
//this.adsActive_ = false;
this.updateChrome_();
};
Application.prototype.pauseForAd = function() {
this.adsActive_ = true;
this.playing_ = true;
this.videoPlayer_.pause();
this.updateChrome_();
};
Application.prototype.adClicked = function() {
this.updateChrome_();
};
Application.prototype.bind_ = function(thisObj, fn) {
return function() {
fn.apply(thisObj, arguments);
};
};
Application.prototype.onSampleAdTagClick_ = function() {
this.adTagBox_.value = this.SAMPLE_AD_TAG_;
};
Application.prototype.onClick_ = function() {
if (!this.adsDone_) {
// if (this.adTagBox_.value == '') {
// this.log('Error: please fill in an ad tag');
// return;
// } else {
// this.adTagUrl_ = this.adTagBox_.value;
// }
if($('#MatchCommentaryScreen').css('display') == 'block' || $('#liveMatchContent').css('display') == 'block')
{
$('#MatchCommentaryScreen').hide();
$('#leftAd').hide();
$('#footer').hide();
// Old UI
$('#liveMatchContent').hide();
$('#leftAd').hide();
$('#adslot_1').hide();
$('#adslot_top').hide();
}
this.adTagUrl_ = this.SAMPLE_AD_TAG_;
// This was breaking the match day if there was no video
if(!this.ads_)
{
return
}
// The user clicked/tapped - inform the ads controller that this code
// is being run in a user action thread.
this.ads_.initialUserAction();
// At the same time, initialize the content player as well.
// When content is loaded, we'll issue the ad request to prevent it
// from interfering with the initialization. See
// for more information.
this.videoPlayer_.preloadContent(this.bind_(this, this.loadAds_));
this.adsDone_ = true;
return;
}
if (this.adsActive_) {
if (this.playing_) {
this.ads_.pause();
} else {
this.ads_.resume();
}
} else {
if (this.playing_) {
this.videoPlayer_.pause();
} else {
this.videoPlayer_.play();
}
}
this.playing_ = !this.playing_;
this.updateChrome_();
};
Application.prototype.onFullscreenClick_ = function() {
if (this.fullscreen) {
// The video is currently in fullscreen mode
var cancelFullscreen = document.exitFullscreen ||
document.exitFullScreen ||
document.webkitCancelFullScreen ||
document.mozCancelFullScreen;
if (cancelFullscreen) {
cancelFullscreen.call(document);
} else {
this.onFullscreenChange_();
}
} else {
// Try to enter fullscreen mode in the browser
var requestFullscreen = document.documentElement.requestFullscreen ||
document.documentElement.webkitRequestFullscreen ||
document.documentElement.mozRequestFullscreen ||
document.documentElement.requestFullScreen ||
document.documentElement.webkitRequestFullScreen ||
document.documentElement.mozRequestFullScreen;
if (requestFullscreen) {
this.fullscreenWidth = window.screen.width;
this.fullscreenHeight = window.screen.height;
requestFullscreen.call(document.documentElement);
} else {
this.fullscreenWidth = window.innerWidth;
this.fullscreenHeight = window.innerHeight;
this.onFullscreenChange_();
}
}
requestFullscreen.call(document.documentElement);
};
Application.prototype.updateChrome_ = function() {
if (this.playing_) {
this.playButton_.textContent = 'II';
} else {
// Unicode play symbol.
this.playButton_.textContent = String.fromCharCode(9654);
}
};
Application.prototype.loadAds_ = function() {
this.ads_.requestAds(this.adTagUrl_);
};
Application.prototype.onFullscreenChange_ = function() {
if (this.fullscreen) {
// The user just exited fullscreen
// Resize the ad container
this.ads_.resize(
this.videoPlayer_.width,
this.videoPlayer_.height);
// Return the video to its original size and position
this.videoPlayer_.resize(
'relative',
'',
'',
this.videoPlayer_.width,
this.videoPlayer_.height);
this.fullscreen = false;
} else {
// The fullscreen button was just clicked
// Resize the ad container
var width = this.fullscreenWidth;
var height = this.fullscreenHeight;
this.makeAdsFullscreen_();
// Make the video take up the entire screen
this.videoPlayer_.resize('absolute', 0, 0, width, height);
this.fullscreen = true;
}
};
Application.prototype.makeAdsFullscreen_ = function() {
this.ads_.resize(
this.fullscreenWidth,
this.fullscreenHeight);
};
Application.prototype.onContentEnded_ = function() {
$('#videocontainer').hide();
$('#MatchCommentaryScreen').show();
$('#quickLinks').show();
$('nav .container').show(); // Show top nav content
$('aside div').show(); // Show left menu content
$('aside ul').show(); // Show left menu content
$('aside .sub-menu ul').css('display', 'none'); // Collapse all Left menu items
//$('#leftAd').show();
//$('#footer').show();
// Old UI
$('#liveMatchContent').show();
$('#adslot_1').show();
$('#adslot_1').css('visibility', 'visible');
$('#adslot_top').show();
// Old UI
$('#liveMatchContent').show();
$('#adslot_1').show();
$('#adslot_1').css('visibility', 'visible');
$('#adslot_top').show();
this.ads_.contentEnded();
};
// Copyright 2013 Google Inc. All Rights Reserved.
// You may study, modify, and use this example for any purpose.
// Note that this example is provided "as is", WITHOUT WARRANTY
// of any kind either expressed or implied.
/**
* Shows how to use the IMA SDK to request and display ads.
*/
var Ads = function(application, videoPlayer) {
this.application_ = application;
this.videoPlayer_ = videoPlayer;
this.contentCompleteCalled_ = false;
// Call setLocale() to localize language text and downloaded swfs
// google.ima.settings.setLocale('fr');
this.adDisplayContainer_ =
new google.ima.AdDisplayContainer(this.videoPlayer_.adContainer);
this.adsLoader_ = new google.ima.AdsLoader(this.adDisplayContainer_);
this.adsManager_ = null;
this.adsLoader_.addEventListener(
google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,
this.onAdsManagerLoaded_,
false,
this);
this.adsLoader_.addEventListener(
google.ima.AdErrorEvent.Type.AD_ERROR,
this.onAdError_,
false,
this);
};
// On iOS and Android devices, video playback must begin in a user action.
// AdDisplayContainer provides a initialize() API to be called at appropriate
// time.
// This should be called when the user clicks or taps.
Ads.prototype.initialUserAction = function() {
this.adDisplayContainer_.initialize();
};
Ads.prototype.requestAds = function(adTagUrl) {
var adsRequest = new google.ima.AdsRequest();
adsRequest.adTagUrl = adTagUrl;
adsRequest.linearAdSlotWidth = this.videoPlayer_.width;
adsRequest.linearAdSlotHeight = this.videoPlayer_.height;
adsRequest.nonLinearAdSlotWidth = this.videoPlayer_.width;
adsRequest.nonLinearAdSlotHeight = this.videoPlayer_.height;
this.adsLoader_.requestAds(adsRequest);
};
Ads.prototype.pause = function() {
if (this.adsManager_) {
this.adsManager_.pause();
}
};
Ads.prototype.resume = function() {
if (this.adsManager_) {
this.adsManager_.resume();
}
};
Ads.prototype.resize = function(width, height) {
if (this.adsManager_) {
this.adsManager_.resize(width, height, google.ima.ViewMode.FULLSCREEN);
}
};
Ads.prototype.contentEnded = function() {
this.contentCompleteCalled_ = true;
this.adsLoader_.contentComplete();
};
Ads.prototype.onAdsManagerLoaded_ = function(adsManagerLoadedEvent) {
this.application_.log('Ads loaded.');
this.adsManager_ = adsManagerLoadedEvent.getAdsManager(
this.videoPlayer_.contentPlayer);
this.processAdsManager_(this.adsManager_);
};
Ads.prototype.processAdsManager_ = function(adsManager) {
// Attach the pause/resume events.
adsManager.addEventListener(
google.ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED,
this.onContentPauseRequested_,
false,
this);
adsManager.addEventListener(
google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED,
this.onContentResumeRequested_,
false,
this);
// Handle errors.
adsManager.addEventListener(
google.ima.AdErrorEvent.Type.AD_ERROR,
this.onAdError_,
false,
this);
var events = [google.ima.AdEvent.Type.ALL_ADS_COMPLETED,
google.ima.AdEvent.Type.CLICK,
google.ima.AdEvent.Type.COMPLETE,
google.ima.AdEvent.Type.FIRST_QUARTILE,
google.ima.AdEvent.Type.LOADED,
google.ima.AdEvent.Type.MIDPOINT,
google.ima.AdEvent.Type.PAUSED,
google.ima.AdEvent.Type.STARTED,
google.ima.AdEvent.Type.THIRD_QUARTILE];
for (var index in events) {
adsManager.addEventListener(
events[index],
this.onAdEvent_,
false,
this);
}
var initWidth, initHeight;
if (this.application_.fullscreen) {
initWidth = this.application_.fullscreenWidth;
initHeight = this.application_.fullscreenHeight;
} else {
initWidth = this.videoPlayer_.width;
initHeight = this.videoPlayer_.height;
}
adsManager.init(
initWidth,
initHeight,
google.ima.ViewMode.NORMAL);
adsManager.start();
//adsManager.setVolume(0); // Mute sound
};
Ads.prototype.onContentPauseRequested_ = function(adErrorEvent) {
this.application_.pauseForAd();
};
Ads.prototype.onContentResumeRequested_ = function(adErrorEvent) {
// Without this check the video starts over from the beginning on a
// post-roll's CONTENT_RESUME_REQUESTED
if (!this.contentCompleteCalled_) {
$('#videocontainer').hide();
$('#MatchCommentaryScreen').show();
$('#quickLinks').show();
$('nav .container').show(); // Show top nav content
$('aside div').show(); // Show left menu content
$('aside ul').show(); // Show left menu content
$('aside .sub-menu ul').css('display', 'none'); // Collapse all Left menu items
//$('#leftAd').show();
//$('#footer').show();
// Old UI
$('#liveMatchContent').show();
$('#adslot_1').show();
$('#adslot_1').css('visibility', 'visible');
$('#adslot_top').show();
}
};
Ads.prototype.onAdEvent_ = function(adEvent) {
this.application_.log('Ad event: ' + adEvent.type);
if (adEvent.type == google.ima.AdEvent.Type.CLICK) {
this.application_.adClicked();
}
if (adEvent.type == google.ima.AdEvent.Type.USER_CLOSE) {
if (this.adsManager_) {
this.adsManager_.destroy();
}
$('#videocontainer').hide();
$('#MatchCommentaryScreen').show();
$('#quickLinks').show();
$('nav .container').show(); // Show top nav content
$('aside div').show(); // Show left menu content
$('aside ul').show(); // Show left menu content
$('aside .sub-menu ul').css('display', 'none'); // Collapse all Left menu items
//$('#leftAd').show();
//$('#footer').show();
// Old UI
$('#liveMatchContent').show();
$('#adslot_1').show();
$('#adslot_1').css('visibility', 'visible');
$('#adslot_top').show();
}
if (adEvent.type == google.ima.AdEvent.Type.SKIPPED) {
if (this.adsManager_) {
this.adsManager_.destroy();
}
$('#videocontainer').hide();
$('#MatchCommentaryScreen').show();
$('#quickLinks').show();
$('nav .container').show(); // Show top nav content
$('aside div').show(); // Show left menu content
$('aside ul').show(); // Show left menu content
$('aside .sub-menu ul').css('display', 'none'); // Collapse all Left menu items
//$('#leftAd').show();
//$('#footer').show();
// Old UI
$('#liveMatchContent').show();
$('#adslot_1').show();
$('#adslot_1').css('visibility', 'visible');
$('#adslot_top').show();
if (this.adsManager_) {
this.adsManager_.destroy();
}
}
if (adEvent.type == google.ima.AdEvent.Type.COMPLETE) {
if (this.adsManager_) {
this.adsManager_.destroy();
}
$('#videocontainer').hide();
$('#MatchCommentaryScreen').show();
$('#quickLinks').show();
$('nav .container').show(); // Show top nav content
$('aside div').show(); // Show left menu content
$('aside ul').show(); // Show left menu content
$('aside .sub-menu ul').css('display', 'none'); // Collapse all Left menu items
//$('#leftAd').show();
//$('#footer').show();
// Old UI
$('#liveMatchContent').show();
$('#adslot_1').show();
$('#adslot_1').css('visibility', 'visible');
$('#adslot_top').show();
}
if (adEvent.type == google.ima.AdEvent.Type.ALL_ADS_COMPLETED) {
if (this.adsManager_) {
this.adsManager_.destroy();
}
$('#videocontainer').hide();
$('#MatchCommentaryScreen').show();
$('#quickLinks').show();
$('nav .container').show(); // Show top nav content
$('aside div').show(); // Show left menu content
$('aside ul').show(); // Show left menu content
$('aside .sub-menu ul').css('display', 'none'); // Collapse all Left menu items
//$('#leftAd').show();
//$('#footer').show();
// Old UI
$('#liveMatchContent').show();
$('#adslot_1').show();
$('#adslot_1').css('visibility', 'visible');
$('#adslot_top').show();
}
};
Ads.prototype.onAdError_ = function(adErrorEvent) {
this.application_.log('Ad error: ' + adErrorEvent.getError().toString());
if (this.adsManager_) {
this.adsManager_.destroy();
}
//this.application_.resumeAfterAd();
$('#videocontainer').hide();
$('#MatchCommentaryScreen').show();
$('#quickLinks').show();
$('nav .container').show(); // Show top nav content
$('aside div').show(); // Show left menu content
$('aside ul').show(); // Show left menu content
$('aside .sub-menu ul').css('display', 'none'); // Collapse all Left menu items
//$('#leftAd').show();
//$('#footer').show();
// Old UI
$('#liveMatchContent').show();
$('#adslot_1').show();
$('#adslot_1').css('visibility', 'visible');
$('#adslot_top').show();
};
// Copyright 2013 Google Inc. All Rights Reserved.
// You may study, modify, and use this example for any purpose.
// Note that this example is provided "as is", WITHOUT WARRANTY
// of any kind either expressed or implied.
/**
* Handles video player functionality.
*/
var VideoPlayer = function() {
this.contentPlayer = document.getElementById('videocontent');
this.adContainer = document.getElementById('adcontainer');
this.videoPlayerContainer_ = document.getElementById('videoplayer');
this.width = 640;
this.height = 360;
};
VideoPlayer.prototype.preloadContent = function(contentLoadedAction) {
// // If this is the initial user action on iOS or Android device,
// // simulate playback to enable the video element for later program-triggered
// // playback.
if (this.isMobilePlatformiPhone()) {
// this.contentPlayer.addEventListener(
// 'loadedmetadata',
// contentLoadedAction,
// false);
// this.contentPlayer.load();
// contentLoadedAction();
$('#videocontainer').hide();
$('#MatchCommentaryScreen').show();
$('#quickLinks').show();
$('nav .container').show(); // Show top nav content
$('aside div').show(); // Show left menu content
$('aside ul').show(); // Show left menu content
$('aside .sub-menu ul').css('display', 'none'); // Collapse all Left menu items
//$('#leftAd').show();
//$('#footer').show();
// Old UI
$('#liveMatchContent').show();
$('#adslot_1').show();
$('#adslot_1').css('visibility', 'visible');
$('#adslot_top').show();
} else {
contentLoadedAction();
}
};
};
VideoPlayer.prototype.pause = function() {
this.contentPlayer.pause();
};
VideoPlayer.prototype.isMobilePlatformiPhone = function() {
return this.contentPlayer.paused &&
(navigator.userAgent.match(/iPhone/));
};
VideoPlayer.prototype.isMobilePlatform = function() {
return this.contentPlayer.paused &&
(navigator.userAgent.match(/(iPod|iPhone|iPad)/) ||
navigator.userAgent.toLowerCase().indexOf('android') > -1);
};
VideoPlayer.prototype.resize = function(
position, top, left, width, height) {
this.videoPlayerContainer_.style.position = position;
this.videoPlayerContainer_.style.top = top + 'px';
this.videoPlayerContainer_.style.left = left + 'px';
this.videoPlayerContainer_.style.width = width + 'px';
this.videoPlayerContainer_.style.height = height + 'px';
this.contentPlayer.style.width = width + 'px';
this.contentPlayer.style.height = height + 'px';
};
VideoPlayer.prototype.registerVideoEndedCallback = function(callback) {
this.contentPlayer.addEventListener(
'ended',
callback,
false);
};
var application = null;