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:
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!