只有当存在创意时才加载视频播放器



我在Google AdManager中创建了一个视频广告单元。手册在这里:https://support.google.com/admanager/answer/1181016?hl=en.我在我的Radiant Player中使用了生成的AdTagUrl(我想将其用于文章中包含的视频广告(。手册在这里:https://www.radiantmediaplayer.com/docs/latest/outstream-video-ads.html.它还可以。但只有当AdManager发送一个创意时。当AdManager没有发送创意时,我必须隐藏玩家。

如果AdManager在加载播放器之前发送了创意,有没有办法检测?

例如:

function showOutstreamVideo()
{
//detect if there is an advertisement
var x = new XMLHttpRequest();
x.open("GET", AdTagUrl, true);
x.onreadystatechange = function () {
if (x.readyState == 4 && x.status == 200)
{
var vast = x.responseXML;
if(vast.getElementsByTagName("Ad").length>0)
{   //code for read, init and place player
}
}
}

但我无法用这个巨大的对象初始化Radiant Player。当我再次使用adTagUrl时,对于AdManager来说,这将是第二印象,可能会有所不同。有没有解决方案可以防止页面在没有创意的情况下不必要地请求播放器脚本?

谢谢和抱歉我的英语

您是否尝试过动态加载Radiant Player?

var settings = {};
var vast = x.responseXML;
if(vast.getElementsByTagName("Ad").length>0) {
var player = document.createElement('script');
player.src = "https://cdn.radiantmediatechs.com/rmp/5.10.6/js/rmp.min.js";
document.body.appendChild(player);
var elementID = 'rmpPlayer';
var rmp = new RadiantMP(elementID);
rmp.init(settings);
}

AdResponse:vast,(作为字符串(是玩家设置中的正确选择。

var x = new XMLHttpRequest();
x.open("GET", outstreamAdTagUrl, true);
x.onreadystatechange = function ()
{   if (x.readyState == 4 && x.status == 200)
{   vast = x.responseText; //x.responeXML;
//if(vast.getElementsByTagName("Ad").length>0)
if(vast.length > 200) //it should be sufficient to determine if it is an ad or an empty VAST
{   //read and init player
var player = document.createElement('script');
document.body.appendChild(player);
player.onload = function(){runOutstream(vast);};
player.setAttribute('src', 'https://cdn.radiantmediatechs.com/rmp/5.10.6/js/rmp.min.js');
}
}
};
x.send(null);
function runOutstream(vast)
{
var settings = {
... license key etc...
autoplay: true,
adOutStreamMutedAutoplay: true,
ads: true,
//adsResponse: new XMLSerializer().serializeToString(vast), //when using responseXML()
adsResponse: vast,
adOutStream: true,
skin: 'outstream',
...other setting
};
var rmp = new RadiantMP('rmpPlayer');
rmp.init(settings);
}

相关内容

  • 没有找到相关文章

最新更新