Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
rockstar1
Level 7

Play VAST midroll and Postroll in Roku

Hi, From quite a few time I am trying to integrate VAST in my roku code, but unfortunately so far i was able to just display the preroll ads using
Library "Roku_Ads.brs"

sub Main(params)
print "11111"
' 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 ad playback,
' so just create a new instance of the screen...
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()
adIface.setAdUrl("http://pubads.g.doubleclick.net/gampad/ads?slotname=/124319096/external/ad_rule_samples&sz=640x480&ciu_szs=300x250&unviewed_position_start=1&output=xml_vast3&impl=s&env=vp&gdfp_req=1&ad_rule=0&vad_type=linear&vpos=preroll&pod=1&ppos=1&lip=true&min_ad_duration=0&max_ad_duration=30000&cust_params=deployment%3Ddevsite%26sample_ar%3Dpremidpost&url=&video_doc_id=short_onecue&cmsid=496&kfa=0&tfcd=0")
adPods = adIface.getAds()
playContent = adIface.showAds(adPods) ' show preroll ad pod (if any)

curPos = 0
if playContent
videoScreen = PlayVideoContent(videoContent)
end if

closingContentScreen = false
contentDone = false
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

if not closingContentScreen ' don't check for any more ads while waiting for screen close
if videoMsg.isScreenClosed() ' roVideoScreen sends this message last for all exit conditions
playContent = false
else if videoMsg.isFullResult()
contentDone = true ' don't want to resume playback after postroll ads
end if

' check for midroll/postroll ad pods
adPods = adIface.getAds(videoMsg)
if adPods <> invalid and adPods.Count() > 0
' must completely close content screen before showing ads
' for some Roku platforms (e.g., RokuTV), calling Close() will not synchronously
' close the media player and may prevent a new media player from being created
' until the screen is fully closed (app has received the isScreenClosed() event)
videoScreen.Close()
closingContentScreen = true
end if
else if videoMsg.isScreenClosed()
closingContentScreen = false ' now safe to render ads
end if ' closingContentScreen

if not closingContentScreen and adPods <> invalid and adPods.Count() > 0
' now safe to render midroll/postroll ads
playContent = adIface.showAds(adPods)
playContent = playContent and not contentDone
if playContent
' resume video playback after midroll ads
videoContent.PlayStart = curPos
videoScreen = PlayVideoContent(videoContent)
end if
end if ' !closingContentScreen
end if ' roVideoScreenEvent
end while
if type(videoScreen) = "roVideoScreen" then videoScreen.Close()
End Sub


Here i understand that setAdUrl is any VMAP url or single VAST URL. My problem is that I have three VAST url, each needed to be played as pre roll, mid roll and post roll. There is no single XML file which fetches these VAST Urls. Using the above i was able to play pre roll. For midroll I searched and get

adBreakSchedule = [adBreakTime1, adBreakTime2, adBreakTime3]
scheduledPods = []
adBreakIndex = 0
for each ad in adPods[0].ad
' schedule one ad per ad break
scheduledPods.Push({viewed : false,
renderSequence : "midroll",
duration : ad.duration,
renderTime : adBreakSchedule[adBreakIndex],
ads : [ad]
})
adBreakIndex = adBreakIndex + 1
end for


But there is no proper implementation of this on Net or forum. Secondly i tried creating my own custom xml file and use those three VAST Url. I know how to fetch the xml in file system, but i was wondering how to create one by myself and place it in setAdUrl like this
 adIface.setAdUrl("file://pkg:/vast.xml")


Need help.
0 Kudos
3 Replies
Elijah_Baley
Level 8

Re: Play VAST midroll and Postroll in Roku

You need to ask that in the developer's forum, not here.
Two Roku Ultras, three Roku 3s and a Roku 1
"Part of the secret of success in life is to eat what you like and let the food fight it out inside." Mark Twain
Van Roy's Law: An unbreakable toy is useful for breaking other toys.
0 Kudos
RokuShawnS
Level 10

Re: Play VAST midroll and Postroll in Roku

Topic moved.

C. Shawn Smith
C. Shawn Smith
Community Liaison

------------
The Cosmos is all that is, and all that was, and ever will be. -- Carl Sagan
0 Kudos
BCVatOVG
Level 7

Re: Play VAST midroll and Postroll in Roku

So there are many ways to do this. Do you want to create a VMAP xml? I am not sure that setAdUrl will take a local XML file, but I have not tested it.

I have a similar issue in which I need tracking (that I could not provide int the VMAP) so I implemented my own function that acts as a callback to a video playing. I set a listener to the video position so It gets called every second and checks to see if it is time to play midroll. If it is, I use adIface.setAdUrl() with the VAST url I have and then call adPods=adIface.getAds() and if that returns true, then I call adIface.showAds(adPods) to play the ads.

I think there is a way to create and structure your own adPods to play through RAF, but I never got that working correctly. I would look at the topics "Sequential Rendering" and "Custom Scheduling" as well as "Custom Ad Rendering".

I read through this MANY MANY times while getting ads to play correctly on my app. https://sdkdocs.roku.com/display/sdkdoc ... +Framework
0 Kudos