drsteveallen
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2014
12:28 AM
Preroll Ads
I need assistance customizing the videoplayer example with the VAST demo to add preroll functionality. Here is what I've done so far:
1. Added NWM_VAST.brs, VAST_VideoScreen.brs, and NWM_Utilities.brs to my project.
2. I placed the following code in appMain:
3. I replaced appVideoScreen.brs with VAST_VideoScreen. This is the code I am using:
I have spent hours over the past severals days attempting to implement preroll ads. I've read the blog post detailing preroll ads MANY times, and I've done a lot of reading and research too. Practical help would be very appreciated!
1. Added NWM_VAST.brs, VAST_VideoScreen.brs, and NWM_Utilities.brs to my project.
2. I placed the following code in appMain:
vast = NWM_VAST()
vastURL = "http://myXML.com/ads.xml"
util = NWM_Utilities()
raw = util.GetStringFromURL(vastURL)
vast.Parse(raw)
if vast.ads.Count() > 0 and vast.ads[0].video <> invalid
video.preroll = vast.ads[0].video
end if
3. I replaced appVideoScreen.brs with VAST_VideoScreen. This is the code I am using:
sub PlayVideo(video)
canvas = CreateObject("roImageCanvas")
canvas.SetMessagePort(CreateObject("roMessagePort"))
canvas.SetLayer(1, {color: "#000000"})
canvas.Show()
' play the pre-roll
adCompleted = true
if video.preroll <> invalid
adCompleted = ShowPreRoll(canvas, video.preroll)
end if
if adCompleted
' if the ad completed without the user pressing UP, play the content
ShowVideoScreen(video)
end if
canvas.Close()
end sub
sub ShowVideoScreen(episode)
screen = CreateObject("roVideoScreen")
screen.SetMessagePort(CreateObject("roMessagePort"))
screen.SetPositionNotificationPeriod(1)
screen.SetContent(episode)
screen.Show()
while true
msg = wait(0, screen.GetMessagePort())
if msg <> invalid
if msg.isScreenClosed()
exit while
end if
end if
end while
screen.Close()
end sub
function ShowPreRoll(canvas, ad)
result = true
player = CreateObject("roVideoPlayer")
' be sure to use the same message port for both the canvas and the player
player.SetMessagePort(canvas.GetMessagePort())
player.SetDestinationRect(canvas.GetCanvasRect())
player.SetPositionNotificationPeriod(1)
' set up some messaging to display while the pre-roll buffers
canvas.SetLayer(2, {text: "Your program will begin after this message"})
canvas.Show()
player.AddContent(ad)
player.Play()
while true
msg = wait(0, canvas.GetMessagePort())
if type(msg) = "roVideoPlayerEvent"
if msg.isFullResult()
exit while
else if msg.isPartialResult()
exit while
else if msg.isRequestFailed()
print "isRequestFailed"
exit while
else if msg.isStatusMessage()
if msg.GetMessage() = "start of play"
' once the video starts, clear out the canvas so it doesn't cover the video
canvas.ClearLayer(2)
canvas.SetLayer(1, {color: "#00000000", CompositionMode: "Source"})
canvas.Show()
end if
etc...
I have spent hours over the past severals days attempting to implement preroll ads. I've read the blog post detailing preroll ads MANY times, and I've done a lot of reading and research too. Practical help would be very appreciated!
4 REPLIES 4


Roku Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2014
09:04 AM
Re: Preroll Ads
Just replacing one video screen with the other is unlikely to work. And I don't see where you're calling PlayVideo() in the first chunk of code, after building the preroll.
Can you describe the problems your having in more detail? Maybe share a crash log or the console output associated with the bad behavior?
Can you describe the problems your having in more detail? Maybe share a crash log or the console output associated with the bad behavior?
jkanter
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2014
11:57 AM
Re: Preroll Ads
Can someone from Roku please contact me regarding these VAST files? I am looking to run ads using VAST and these would be an incredible help. Thanks!!!

RokuJoel
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2014
03:52 PM
Re: Preroll Ads
veetowner
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2015
10:37 AM
Re: Preroll Ads
Just want clarification on the right to use this library.
"To this purpose, this library is designed to facilitate advanced targeting and inventory optimization for any ads served by Roku. Even if all ads are served by a third party ad provider, it is advantageous to fully implement this library should Roku have an advertising agreement with you in the future."
Can anybody use this library for running VAST video ads? Can it be included in the 3rd party library this is provided to developer?
"To this purpose, this library is designed to facilitate advanced targeting and inventory optimization for any ads served by Roku. Even if all ads are served by a third party ad provider, it is advantageous to fully implement this library should Roku have an advertising agreement with you in the future."
Can anybody use this library for running VAST video ads? Can it be included in the 3rd party library this is provided to developer?