Your Digital Media Has Never Looked So Good

 
drsteveallen
Topic Author
Posts: 1
Joined: Thu Jan 30, 2014 2:16 pm

Preroll Ads

Fri Jan 31, 2014 1:28 am

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!
 
User avatar
RokuChris
Posts: 1166
Joined: Mon Aug 30, 2010 1:45 pm

Re: Preroll Ads

Fri Jan 31, 2014 10:04 am

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?
 
jkanter
Posts: 4
Joined: Thu Oct 17, 2013 1:14 am

Re: Preroll Ads

Tue Feb 18, 2014 12:57 pm

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!!!
 
User avatar
RokuJoel
Posts: 1758
Joined: Mon Nov 14, 2011 5:22 pm

Re: Preroll Ads

Wed Feb 19, 2014 4:52 pm

Hi, here is a link to RokuChris' VAST example:
https://www.box.com/s/w4dqiolhdapsdohkaa0z

- Joel
 
veetowner
Posts: 2
Joined: Wed Mar 04, 2015 11:31 am

Re: Preroll Ads

Wed Mar 04, 2015 11:37 am

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?

Who is online

Users browsing this forum: No registered users and 7 guests