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: 
newchannel
Roku Guru

Pre-roll video question & Display Ads?

I read the blog entry about adding pre-roll video but where within the code does this snippet of code get added? Do I copy the code from the blog and paste it where?

Any help on adding pre-roll is appreciated.

Also, if you have added display ads to your posterscreens that can be changed from the server side, I appreciate some help with how to do this also.

Thanks in advance much!
http://www.victoryNOWfilmsandtv.com
0 Kudos
16 REPLIES 16
milesplit
Visitor

Re: Pre-roll video question & Display Ads?

The blog post has an email address in it. Email them and they'll get back to you. I did the same thing recently and have preroll running in my channel with the code they supplied. You'll want the VAST 1.05 code (not 1.01 which they originally sent) if you have doubleclick or CAST compatible ad server.
0 Kudos
destruk
Streaming Star

Re: Pre-roll video question & Display Ads?

For the code on the blog post, the preroll function can go anywhere, the other code goes where you would normally have your video play.
0 Kudos
newchannel
Roku Guru

Re: Pre-roll video question & Display Ads?

I'm guessing here but this code from the blog entry.... do I place it on the appdetails.brs? And, where does the url go for the pre-roll video?

function ShowPreRoll(video)
' a true result indicates that playback finished without user intervention
' a false result indicates that the user pressed UP or BACK to terminate playback
result = true
canvas = CreateObject("roImageCanvas")
player = CreateObject("roVideoPlayer")
port = CreateObject("roMessagePort")

canvas.SetMessagePort(port)
' build a very simple buffer screen for our preroll video
canvas.SetLayer(0, { text: "Your program will begin after this message" })
canvas.Show()

' be sure to use the same message port for both the canvas and the player
' so we can receive events from both
player.SetMessagePort(port)
player.SetDestinationRect(canvas.GetCanvasRect())
player.AddContent(video)

player.Play()

' start our event loop
while true
' wait for an event
msg = wait(0, canvas.GetMessagePort())

if type(msg) = "roVideoPlayerEvent"
if msg.isFullResult()
' the video played to the end without user intervention
exit while
else if isRequestFailed()
' something went wrong with playback, but the user did not intervene
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.SetLayer(0, { color: "#00000000", CompositionMode: "Source" })
canvas.Show()
end if
end if
else if type(msg) = "roImageCanvasEvent"
if msg.isRemoteKeyPressed()
index = msg.GetIndex()
if index = 0 or index = 2
' the user pressed UP or BACK to terminate playback
result = false
exit while
end if
end if
end if
end while

player.Stop()
canvas.Close()

return result
end function



And where does this next part of the code go:

' create and display a blank roImageCanvas to prevent the
' underlying UI from flickering between videos
canvas = CreateObject("roImageCanvas")
canvas.SetLayer(0, "#000000")
canvas.Show()

' play the preroll video with trick play disabled
if ShowPreroll(preroll)
' only play the main content if the preroll completed without user intervention
ShowVideoScreen(content)
end if

' close the blank canvas and return the user to the previous UI screen
canvas.Close()
http://www.victoryNOWfilmsandtv.com
0 Kudos
destruk
Streaming Star

Re: Pre-roll video question & Display Ads?

The first section is a function, so it goes anywhere.
The second part requires a value for "video" before the function is used.
if ShowPreroll(preroll)

Preroll is defined above both parts of the code on the blog page.
0 Kudos
bandal
Visitor

Re: Pre-roll video question & Display Ads?

The part that is not understood well is how to call or play our many videos that is in our xml files after the Pre-Roll video plays. Plus, better to call the Pre-Roll in a xml or php file as it is easier to change a pre-roll video than the hard coded part in the .brs files.
Any hints for that?
0 Kudos
RokuChris
Roku Employee
Roku Employee

Re: Pre-roll video question & Display Ads?

"bandal" wrote:
The part that is not understood well is how to call or play our many videos that is in our xml files after the Pre-Roll video plays. Plus, better to call the Pre-Roll in a xml or php file as it is easier to change a pre-roll video than the hard coded part in the .brs files.
Any hints for that?


Pulling the ad data from a cloud service and using it to construct a content-meta-data structure are left to the developer and not covered on the blog because that step could be different for each implementation. How to get an ad from your ad provider will depend on how the provider exposes their data to your channel.

Like milesplit said, If your ad provider supports VAST, we do have a BrightScript class that I can share for parsing VAST into a content-meta-data structure.
0 Kudos
bandal
Visitor

Re: Pre-roll video question & Display Ads?

Regarding PreRoll I added the function for showPreroll into its own appPreRoll.brs file and in appVideoScreen.brs I have added this section, but always errors out on the line preroll = { line 142 in my script
Any idea why?
Debug shows this only but the Syntax I cant find an error:
*** ERROR compiling /pkg:/source/appVideoScreen.brs:
Syntax Error. (compile error &h02) in ...kg:/source/appVideoScreen.brs(142)
.
.
.
preroll = {
streamFormat: "mp4"
stream: {
url: "http://www.archive.org/download/kelloggs_variety_pak/kelloggs_variety_pak_512kb.mp4"
}
}
ShowVideoScreen(preroll)
port = CreateObject("roMessagePort")
screen = CreateObject("roVideoScreen")
screen.SetMessagePort(port)
screen.SetContent(preroll)

screen.Show()

while true
msg = wait(0, port)

if type(msg) = "roVideoScreenEvent"
if msg.isScreenClosed()
exit while
end if
end if
end while

screen.Close()
end sub
' Create and display a blank roImageCanvas to prevent the
' underlying UI from flickering between videos after Pre-Roll
canvas = CreateObject("roImageCanvas")
canvas.SetLayer(0, "#000000")
canvas.Show()
' Play the preroll video with trick play disabled

if ShowPreroll(preroll)

Function showVideoScreen(episode As Object)
'*Start to Check if Billing was a successful*************************
' if (not BillReminder()) then return invalid
'*End Check if Billing was successful********************************
if type(episode) <> "roAssociativeArray" then
print "invalid data passed to showVideoScreen"
return -1
endif
'* Start optional Tracking of video content played****************
' Track(episode["contentId"])
'* End optional Tracking of video content played****************
port = CreateObject("roMessagePort")
screen = CreateObject("roVideoScreen")
screen.SetMessagePort(port)

screen.SetPositionNotificationPeriod(30)
screen.SetContent(episode)
screen.Show()

'Uncomment his line to dump the contents of the episode to be played
PrintAA(episode)

while true
msg = wait(0, port)

if type(msg) = "roVideoScreenEvent" then
print "showHomeScreen | msg = "; msg.getMessage() " | index = "; msg.GetIndex()
if msg.isScreenClosed()
print "Screen closed"
exit while
elseif msg.isRequestFailed()
print "Video request failure: "; msg.GetIndex(); " " msg.GetData()
elseif msg.isStatusMessage()
print "Video status: "; msg.GetIndex(); " " msg.GetData()
elseif msg.isButtonPressed()
print "Button pressed: "; msg.GetIndex(); " " msg.GetData()
elseif msg.isPlaybackPosition() then
nowpos = msg.GetIndex()
RegWrite(episode.ContentId, nowpos.toStr())
else
print "Unexpected event type: "; msg.GetType()
end if
else
print "Unexpected message class: "; type(msg)
end if
end while

End Function
' End Pre-Roll
End if
' close the blank canvas and return the user to the previous UI screen
canvas.Close()
0 Kudos
destruk
Streaming Star

Re: Pre-roll video question & Display Ads?

You can't have a function inside another function or subroutine. It needs to be separate. I should have clarified 'anywhere' but I thought you knew that. Sorry for the confusion.
By anywhere - I mean, it makes no difference which brs file the function goes in, and it makes no difference where in whichever file you choose to place it provided a duplicate function or subroutine name doesn't exist elsewhere, and that the function is not within another function or subroutine, as that isn't a legal allowed coding scheme.
0 Kudos
bandal
Visitor

Re: Pre-roll video question & Display Ads?

Ok, so the person who wrote the blog was mistaken then. So preroll is a function is what your saying?
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.