var adsManager; var adsLoader; var adDisplayContainer; var intervalTimer; var playButton; var videoContent; function init() { videoContent = document.getElementById(ima_video_container); // playButton = document.getElementById('playButton'); // playButton.addEventListener('click', playAds);vjs-big-play-button setUpIMA(); $(".ima_overlay").width($("#" + ima_video_container).width()); } function setUpIMA() { // Create the ad display container. createAdDisplayContainer(); // Create ads loader. adsLoader = new google.ima.AdsLoader(adDisplayContainer); adsLoader.addEventListener( google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED, onAdsManagerLoaded, false); adsLoader.addEventListener( google.ima.AdErrorEvent.Type.AD_ERROR, onAdError, false); var contentEndedListener = function () { adsLoader.contentComplete(); }; videoContent.onended = contentEndedListener; // Request video ads. var adsRequest = new google.ima.AdsRequest(); adsRequest.adTagUrl = ima_vast_url; adsRequest.linearAdSlotWidth = $("#" + ima_video_container).width(); adsRequest.linearAdSlotHeight = $("#" + ima_video_container).height(); adsRequest.nonLinearAdSlotWidth = $("#" + ima_video_container).width(); adsRequest.nonLinearAdSlotHeight = $("#" + ima_video_container).height(); adsLoader.requestAds(adsRequest); } function createAdDisplayContainer() { adDisplayContainer = new google.ima.AdDisplayContainer( document.getElementById('adContainer'), videoContent); } function playAds() { videoContent.load(); adDisplayContainer.initialize(); try { adsManager.init($("#" + ima_video_container).width(), $("#" + ima_video_container).height(), google.ima.ViewMode.NORMAL); adsManager.start(); } catch (adError) { videojs('content_video').play(); } } function onAdsManagerLoaded(adsManagerLoadedEvent) { var adsRenderingSettings = new google.ima.AdsRenderingSettings(); adsRenderingSettings.restoreCustomPlaybackStateOnAdBreakComplete = true; adsManager = adsManagerLoadedEvent.getAdsManager(videoContent, adsRenderingSettings); adsManager.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, onAdError); adsManager.addEventListener( google.ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED, onContentPauseRequested); adsManager.addEventListener( google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED, onContentResumeRequested); adsManager.addEventListener( google.ima.AdEvent.Type.ALL_ADS_COMPLETED, onAdEvent); adsManager.addEventListener(google.ima.AdEvent.Type.LOADED, onAdEvent); adsManager.addEventListener(google.ima.AdEvent.Type.STARTED, onAdEvent); adsManager.addEventListener(google.ima.AdEvent.Type.COMPLETE, onAdEvent); } function onAdEvent(adEvent) { console.log(adEvent); var ad = adEvent.getAd(); switch (adEvent.type) { case google.ima.AdEvent.Type.LOADED: if (!ad.isLinear()) { videojs('content_video').play(); } break; case google.ima.AdEvent.Type.STARTED: if (ad.isLinear()) { $(".ima_overlay").fadeIn(); intervalTimer = setInterval( function () { var remainingTime = adsManager.getRemainingTime(); $(".ima_seconds_value").html(remainingTime.toFixed(0)); }, 300); // every 300ms } break; case google.ima.AdEvent.Type.COMPLETE: if (ad.isLinear()) { clearInterval(intervalTimer); } break; case google.ima.AdEvent.Type.CLICK: console.log("clicked ad"); break; } } function onAdError(adErrorEvent) { // Handle the error logging. try { throw "myException"; // Fehler wird ausgelöst } catch (e) { } } function onContentPauseRequested() { videoContent.pause(); } function onContentResumeRequested() { videojs('content_video').play(); $("#video_ad_container").fadeOut(); $("#adContainer").hide(); $(".ima_overlay").fadeOut(); $(".ima_overlay").hide(); $('content_video').css("z-index", "11110000000001"); }