Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
kiranwhiz
Visitor

DFP VMAP midroll ads using RAF

Hi,
I want to implement DFP video ads in my channel. For that I am using RAF. I am testing RokuAdFrameworkSample against sample IMA tags provided in Google IMA docs. The code works fine for preroll VAST ads but its not working for VMAP urls that I got from official IMA docs - https://developers.google.com/interacti ... html5/tags . I got following sample url and its not working:
VMAP Pre-, Mid-, and Post-rolls, Single Ads
Could anyone please explain how to get midrolls working using RAF? Are VMAP tag supported in RAF/Roku to play preroll/midroll/postroll ads? Can you please point me to a resource to implement Midroll ads in a Roku channel?
0 Kudos
9 REPLIES 9
RokuChris
Roku Employee
Roku Employee

Re: DFP VMAP midroll ads using RAF

You probably want the sequential rendering mode described in section 2.1.2 of the RAF doc. http://sdkdocs.roku.com/display/sdkdoc/ ... +Framework

Basically, you want to call GetAds() with each isPlaybackPosition event you get from your video screen and if there are ads that should be played at a given position, they will be returned from that call.
0 Kudos
kiranwhiz
Visitor

Re: DFP VMAP midroll ads using RAF

I am running the midroll ad urls in RAF sample code that I got from Roku website. I tested the url in google IMA video suite ispector and it has a preroll, a midroll and a postroll ad. The code works for preroll url that does not have any midroll ads (single VAST tag). But none of the ads from a VAMP url are playing in following code. When i do print 'adPods.count()' I always get result as 0.
Works for : single, inline, linear ad - http://pubads.g.doubleclick.net/gampad/ ... orrelator=
Does not work for VMAP Pre-, Mid-, and Post-rolls, Single Ads : http://pubads.g.doubleclick.net/gampad/ ... orrelator=

Here is the code:


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
0 Kudos
RokuChris
Roku Employee
Roku Employee

Re: DFP VMAP midroll ads using RAF

What does PlayVideoContent() do? If it has its own event loop and doesn't return until the content finishes, then your check for midroll ads in PlayContentWithAds() will never happen. Or at least won't happen until after PlayVideoContent() returns.

And you should be sure you're calling SetPositionNotificationPeriod(1) on your video screen or you may not get events often enough to trigger the midrolls.

http://sdkdocs.roku.com/display/sdkdoc/ ... dasInteger)asVoid
0 Kudos
kiranwhiz
Visitor

Re: DFP VMAP midroll ads using RAF

Here is code for playContent() method :

Function PlayVideoContent(content as Object) as Object
' roVideoScreen just closes if you try to resume or seek after
' returning from ad playback... TODO: is there a way to make
' this work without resetting the screen object?
videoScreen = CreateObject("roVideoScreen")
videoScreen.SetContent(content)
' need a reasonable notification period set if midroll/postroll ads are to be
' rendered at an appropriate time
videoScreen.SetPositionNotificationPeriod(1)
videoScreen.SetMessagePort(CreateObject("roMessagePort"))
videoScreen.Show()

return videoScreen
End Function


And this entire contents of the main.brs file:

Library "Roku_Ads.brs"

sub Main(params)
' lengthy (20+ min.) TED talk to allow time for testing multiple ad pods
videoContent = { streamFormat : "mp4" }
videoContent.stream = { url: "http://video.ted.com/talks/podcast/DavidKelley_2002_480.mp4",
bitrate: 800,
quality: false
}
PlayContentWithAds(videoContent)
end sub

Function PlayVideoContent(content as Object) as Object
' roVideoScreen just closes if you try to resume or seek after
' returning from ad playback... TODO: is there a way to make
' this work without resetting the screen object?
videoScreen = CreateObject("roVideoScreen")
videoScreen.SetContent(content)
' need a reasonable notification period set if midroll/postroll ads are to be
' rendered at an appropriate time
videoScreen.SetPositionNotificationPeriod(1)
videoScreen.SetMessagePort(CreateObject("roMessagePort"))
videoScreen.Show()

return videoScreen
End Function

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
0 Kudos
RokuChris
Roku Employee
Roku Employee

Re: DFP VMAP midroll ads using RAF

Your code is working for me. I see a preroll, then ~15s of content, then a midroll, then the content resumes at the correct point.
0 Kudos
kiranwhiz
Visitor

Re: DFP VMAP midroll ads using RAF

Thats strange. When I run the app in my Roku 3 it does not work. None of the ads play.
print adPods.count() returns 0. I will keep trying with some other VMAP samples. Thanks a lot for your help 🙂
0 Kudos
kiranwhiz
Visitor

Re: DFP VMAP midroll ads using RAF

Hi,
With above code single preroll and single midroll ads are working for me. I want to show multiple ads during the midroll. This VMAP url has three VAST ads in a midroll but for me its showing only one ad when midroll gets called. http://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/ad_rule_samples&ciu_szs...
How do I play all three ads present in the midroll section in above url one after the other?
0 Kudos
RokuChris
Roku Employee
Roku Employee

Re: DFP VMAP midroll ads using RAF

"kiranwhiz" wrote:
Hi,
With above code single preroll and single midroll ads are working for me. I want to show multiple ads during the midroll. This VMAP url has three VAST ads in a midroll but for me its showing only one ad when midroll gets called. http://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/ad_rule_samples&ciu_szs...
How do I play all three ads present in the midroll section in above url one after the other?


Our ad gurus are telling me that what you're seeing is the expected behavior. Your VMAP has multiple ad breaks for the same time slot. In that case, RAF will only play the first one. The VMAP spec says that each <AdBreak> should define a single ad break. Can you share any more detail about your DFP configuration? We're curious how you ended up with that structure. Did you setup 3 ad breaks rather than 1 ad break with 3 ads?

There are 2 things you can try to play multiple ads in a single ad break:

  • The most correct way according to the VMAP spec would be for your <AdBreak> to have a single <AdSource> and for that <AdSource> to contain a URL that returns the VAST for all the ads for that break.

  • RAF will also handle multiple <AdSource> elements within a single <AdBreak>
0 Kudos
kiranwhiz
Visitor

Re: DFP VMAP midroll ads using RAF

Hi,
I am using sample ads urls provided by Google from here - https://developers.google.com/interactive-media-ads/docs/sdks/android/tags?hl=en These urls can be tested using Google's Video Suite Inspector tool - https://developers.google.com/interactive-media-ads/docs/sdks/android/vastinspector .
Can you please provide working sample of vmap file with multiple ads?
I updated the ad break timings (added different time in seconds for each slot in midrolls) here http://html5.whizti.com/vmap.xml but its not working.
0 Kudos