在特定时间暂停视频并显示隐藏的广告

时间:2016-05-02 07:08:10

标签: javascript html5 youtube-javascript-api

我想播放youtube嵌入视频并暂停时间,然后显示隐藏的广告并在点击广告后启动视频。谁能告诉我错误在哪里?



var time_cok = 7.25;
var adhac_mod = 10;
var adhac_tm_min = 20;
var adhac_tm_max = 25;
function setCookie(e,t,a){var r=new Date;r.setTime(r.getTime()+24*a*60*60*1e3);var n="expires="+r.toUTCString();document.cookie=e+"="+t+"; "+n+"; path=/"}function getCookie(e){for(var t=e+"=",a=document.cookie.split(";"),r=0;r<a.length;r++){for(var n=a[r];" "==n.charAt(0);)n=n.substring(1);if(0==n.indexOf(t))return n.substring(t.length,n.length)}return""}function randomIntFromInterval(e,t){return Math.floor(Math.random()*(t-e+1)+e)}function setAdHac(){var e=getCookie("adhac");if(!e){var t={width:"100%",height:"100%",opacity:"0",position:"absolute","z-index":"9998"},a={"minwidth":"400px","max-width":"700px","min-height":"280px",margin:"110px 0 auto",overflow:"hidden","text-align":"center",visibility:"hidden","zindex":"9999"};document.getElementById("ytplayer").innerHTML+="<div></div>",jQuery("#below-ad").css(t),jQuery("#below-ad > div").css(a),jQuery("#belowad").prependTo("#ytplayer"),setCookie("adhac",1,time_cok)}}function onYouTubeIframeAPIReady(){player=new YT.Player("player",{events:{onStateChange:onPlayerStateChange}})}function onPlayerStateChange(e){if(e.data==YT.PlayerState.PLAYING){var t=1e3*randomIntFromInterval(adhac_tm_min,adhac_tm_max);if(2==adhac_mod){var a=player.getDuration(),r=0;60>=a?r=randomIntFromInterval(35,50):a>60&&100>=a?r=randomIntFromInterval(30,40):a>100&&160>=a?r=randomIntFromInterval(20,25):a>160&&(r=randomIntFromInterval(10,15));var n=a*(r/100),t=1e3*Math.round(n)}setTimeout(function(){setAdHac()},t)}}var ytplayer=document.getElementById("ytplayer");if(ytplayer)if(0==adhac_mod)setAdHac();else{var tag=document.createElement("script");tag.src="https://www.youtube.com/iframe_api";var firstScriptTag=document.getElementsByTagName("script")[0];firstScriptTag.parentNode.insertBefore(tag,firstScriptTag);var player}
&#13;
&#13;
&#13;

这是HTML代码

&#13;
&#13;
<!--Youtube Video-->
<div id="ytplayer" style="position: relative; display: inline-block;"><iframe id="player"title="YouTube video player"src="https://www.youtube.com/embed/5PGEWejcmNU?enablejsapi=1&amp;showinfo=0" width="560"
height="315" frameborder="0" allowfullscreen="allowfullscreen"></iframe></div>
<!--AD-->
<div id="below-ad" style="width: 100%; position: relative;"><div style= min-width: 400px; max-width: 700px; min-height: 280px; margin: 0 auto; overflow: hidden; text-align: center; visibility: hidden; zindex:9999;">
AD SCRIPT HERE
</div>
&#13;
&#13;
&#13;

0 个答案:

没有答案