我正在从 Roku 网站获得的 RAF 示例代码中运行插播广告网址。我在谷歌 IMA 视频套件 isspector 中测试了该网址,它有一个前贴片广告、一个插播广告和一个后贴片广告。该代码适用于没有任何插播广告(单个 VAST 标记)的前贴片网址。但是来自 VAMP 网址的广告都没有在以下代码中播放。当我打印“adPods.count()”时,我总是得到结果为 0。适用于:单、内联、线性广告 - http://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096 /external/single_ad_samples&ciu_szs=300x250&impl=s&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1&cust_params=deployment%3Ddevsite%26sample_ct%3Dlinear&correlator=
这是代码:
Sub PlayContentWithAds(videoContent as Object)
canvas = CreateObject("roImageCanvas")
canvas.SetLayer(1, {color: "#000000"})
canvas.SetLayer(2, {text: "Loading..."})
canvas.Show()
adIface = Roku_Ads()
print "Roku_Ads library version: " + adIface.getLibVersion()
' Normally, would set publisher's ad URL here. Otherwise uses default Roku ad server (with single preroll placeholder ad)
adIface.setAdUrl("http://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/ad_rule_samples&ciu_szs=300x250&ad_rule=1&impl=s&gdfp_req=1&env=vp&output=vmap&unviewed_position_start=1&cust_params=deployment%3Ddevsite%26sample_ar%3Dpremidpost&cmsid=496&vid=short_onecue&correlator=")
adPods = adIface.getAds()
print "printing adpods count here.."
print adPods.count()
playContent = adIface.showAds(adPods) ' show preroll ad pod (if any)
curPos = 0
if playContent
videoScreen = PlayVideoContent(videoContent)
end if
while playContent
videoMsg = wait(0, videoScreen.GetMessagePort())
if type(videoMsg) = "roVideoScreenEvent"
if videoMsg.isStreamStarted()
canvas.ClearLayer(2)
end if
if videoMsg.isPlaybackPosition()
' cache current playback position for resume after midroll ads
curPos = videoMsg.GetIndex()
end if
'check for midroll/postroll ad pods
adPods = adIface.getAds(videoMsg)
if adPods <> invalid and adPods.Count() > 0
' stop video playback to prepare for midroll ad render
videoScreen.Close()
playContent = adIface.showAds(adPods)
if playContent
' resume video playback after midroll ads
videoContent.PlayStart = curPos
videoScreen = PlayVideoContent(videoContent)
end if
' if !playContent, User exited ad view, returning to content selection
end if ' adPods <> invalid
if videoMsg.isFullResult() or videoMsg.isRequestFailed() or videoMsg.isPartialResult() or videoMsg.isScreenClosed()
playContent = false
end if
end if ' roVideoScreenEvent
end while
if type(videoScreen) = "roVideoScreen" then videoScreen.Close()
End Sub