0

エラー:広告の再生を開始する前に、広告の再生要素を初期化できませんでした。

表示する広告を取得できません。以前は問題なく動作していましたが、突然このエラーがスローされるようになりました。何年も機能して以来、コードを変更していません。

ゲームの Web サイトでこれを使用し、ビデオ広告を表示し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>

これを使用して:

https://github.com/googleads/googleads-ima-html5

https://developers.google.com/interactive-media-ads/docs/sdks/html5/v3/apis#ima.AdsRequest.setAdWillPlayMuted

4

1 に答える 1