错误:在开始播放广告之前无法初始化广告播放元素。
我们无法向我们展示广告。它曾经工作得很好,然后突然间这个错误现在被抛出。我们没有改变代码,因为它工作了多年。
我们在游戏网站上使用此功能,我们会展示视频广告,然后使用onMediaEnd()
在视频完成或遇到错误后显示游戏。
<script>
var adVideoContainer = document.getElementById('ad-video');
var adDisplayContainer = new google.ima.AdDisplayContainer(adVideoContainer);
var adsLoader = new google.ima.AdsLoader(adDisplayContainer);
adsLoader.addEventListener(google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED, function(adEvent){
console.log('ADS_MANAGER_LOADED');
onAdsManagerLoaded(adEvent);
}, true);
adsLoader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, function(adEvent) {
console.log('AD_ERROR');
onMediaEnd();
},false);
function onAdsManagerLoaded(adEvent)
{
var adsRenderingSettings = new google.ima.AdsRenderingSettings();
var adsManager = adEvent.getAdsManager({
currentTime: 0
});
window.adsManager = adsManager;
adsManager.addEventListener( google.ima.AdErrorEvent.Type.AD_ERROR, function(adEvent) {
console.log('AD_ERROR');
onMediaEnd();
});
adsManager.addEventListener( google.ima.AdEvent.Type.ALL_ADS_COMPLETED, function(adEvent) {
console.log('ALL_ADS_COMPLETED');
onMediaEnd();
});
adsManager.addEventListener( google.ima.AdEvent.Type.COMPLETE, function(adEvent) {
console.log('COMPLETE');
onMediaEnd();
});
adsManager.addEventListener(google.ima.AdEvent.Type.LOADED,function(adEvent){
console.log('LOADED');
var ad = adEvent.getAd();
var adData = adEvent.getAdData();
console.log(adData);
if (!ad.isLinear())
{
// show game content
onMediaEnd();
}
else
{
// Ad is being shown, lets do nothing for now...
}
});
try
{
adsManager.init(640, 480, google.ima.ViewMode.NORMAL);
adsManager.start();
}
catch (adError)
{
// this is currently where the ad keeps failing!
console.log(adError);
onMediaEnd();
}
}
var adsRequest = new google.ima.AdsRequest();
adsRequest.adTagUrl = '<?=$adsenseVASTURL?>';
adsRequest.linearAdSlotWidth = 640;
adsRequest.linearAdSlotHeight = 480;
adsRequest.nonLinearAdSlotHeight = 480;
adsRequest.nonLinearAdSlotWidth = 640;
adsRequest.forceNonLinearFullSlot = true;
/*adsRequest.setAdWillAutoPlay(false);
adsRequest.setAdWillPlayMuted(true);*/
adsLoader.requestAds(adsRequest);
</script>
使用此:
答案 0 :(得分:0)
我在网络游戏(桌面)上遇到了完全相同的事情。 令人惊讶的是,我可以在添加
后再次播放视频广告enemy1.getPosition().equals(player.getGun1Position())
虽然文档说的是this method has no effect on desktop platforms ...
adDisplayContainer.initialize();