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: 
winningsheen
Visitor

Pre Roll Screen?

Hi.. I've stripped out some of the functionality from the Roku blog for the pre roll video. I just need this to display at the start of the channel. Here is my appMain.brs. It plays the video, the home screen doesn't load after.

'********************************************************************
'** Video Player Example Application - Main
'** November 2009
'** Copyright (c) 2009 Roku Inc. All Rights Reserved.
'********************************************************************
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
CanvasPreroll=CreateObject("roImageCanvas")

Port=CreateObject("roMessagePort")

CanvasPreroll.SetMessagePort(Port)
' build a very simple buffer screen for our preroll video
CanvasPreroll.SetLayer()
CanvasPreroll.Close()

' be sure to use the same message port for both the canvas and the player
' so we can receive events from both

End Function

Sub Main()

'initialize theme attributes like titles, logos and overhang color
initTheme()
preroll = {
streamFormat: "mp4"
stream: {
url: "http://www.archive.org/download/kelloggs_variety_pak/kelloggs_variety_pak_512kb.mp4"
}
}
ShowVideoScreen(preroll)

'prepare the screen for display and get ready to begin
screen=preShowHomeScreen("", "")
'set to go, time to get started
if screen=invalid then
print "unexpected error in preShowHomeScreen"
return
end if
showHomeScreen(screen)

End Sub


'*************************************************************
'** Set the configurable theme attributes for the application
'**
'** Configure the custom overhang and Logo attributes
'** Theme attributes affect the branding of the application
'** and are artwork, colors and offsets specific to the app
'*************************************************************

Sub initTheme()

app = CreateObject("roAppManager")
theme = CreateObject("roAssociativeArray")

theme.OverhangOffsetSD_X = "72"
theme.OverhangOffsetSD_Y = "31"
theme.OverhangSliceSD = "pkg:/images/Overhang_Background_SD.png"
theme.OverhangLogoSD = "pkg:/images/Overhang_Logo_SD.png"

theme.OverhangOffsetHD_X = "125"
theme.OverhangOffsetHD_Y = "35"
theme.OverhangSliceHD = "pkg:/images/Overhang_Background_HD.png"
theme.OverhangLogoHD = "pkg:/images/Overhang_Logo_HD.png"
theme.BackgroundColor = "#FFFFFF"
app.SetTheme(theme)

End Sub


Any help would be appreciated! Thanks! 😄
0 Kudos
6 REPLIES 6
RokuChris
Roku Employee
Roku Employee

Re: Pre Roll Screen?

Your channel will exit anytime you close all of its screens. viewtopic.php?f=34&t=33895&p=216863#p216863
0 Kudos
winningsheen
Visitor

Re: Pre Roll Screen?

Okay. I've added the code and it seems to start loading the main screen but it's stuck at "Retrieving".. My code is below:


'********************************************************************
'** Video Player Example Application - Main
'** November 2009
'** Copyright (c) 2009 Roku Inc. All Rights Reserved.
'********************************************************************
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
CanvasPreroll=CreateObject("roImageCanvas")

Port=CreateObject("roMessagePort")

CanvasPreroll.SetMessagePort(Port)
' build a very simple buffer screen for our preroll video
CanvasPreroll.SetLayer()
canvas.Close()
End Function

Sub Main()

'initialize theme attributes like titles, logos and overhang color
initTheme()
preroll = {
streamFormat: "mp4"
stream: {
url: "http://www.archive.org/download/kelloggs_variety_pak/kelloggs_variety_pak_512kb.mp4"
}
}
screenFacade = CreateObject("roPosterScreen")
screenFacade.show()
ShowVideoScreen(preroll)
screen=preShowHomeScreen("", "")
'set to go, time to get started
if screen=invalid then
print "unexpected error in preShowHomeScreen"
return
end if
screenFacade.showMessage("")
showHomeScreen(screen)
sleep(3500)
End Sub


'*************************************************************
'** Set the configurable theme attributes for the application
'**
'** Configure the custom overhang and Logo attributes
'** Theme attributes affect the branding of the application
'** and are artwork, colors and offsets specific to the app
'*************************************************************

Sub initTheme()

app = CreateObject("roAppManager")
theme = CreateObject("roAssociativeArray")

theme.OverhangOffsetSD_X = "72"
theme.OverhangOffsetSD_Y = "31"
theme.OverhangSliceSD = "pkg:/images/Overhang_Background_SD.png"
theme.OverhangLogoSD = "pkg:/images/Overhang_Logo_SD.png"

theme.OverhangOffsetHD_X = "125"
theme.OverhangOffsetHD_Y = "35"
theme.OverhangSliceHD = "pkg:/images/Overhang_Background_HD.png"
theme.OverhangLogoHD = "pkg:/images/Overhang_Logo_HD.png"
theme.BackgroundColor = "#FFFFFF"
app.SetTheme(theme)

End Sub


Im using the videoplayer template. Should the facade go in the function?
0 Kudos
winningsheen
Visitor

Re: Pre Roll Screen?

I've simplified this even further.. The video is laying but it's still exiting the channel. I tried using the facade at different points and it always gives me some sort of error. appMain.brs is below.


'********************************************************************
'** Video Player Example Application - Main
'** November 2009
'** Copyright (c) 2009 Roku Inc. All Rights Reserved.
'********************************************************************
Sub RunUserInterface()
screenFacade = CreateObject("roPosterScreen")
canvas = CreateObject("roVideoScreen")
canvas.SetContent({
Title: "My Video"
StreamFormat: "mp4"
Stream: { URL: "http://www.archive.org/download/kelloggs_variety_pak/kelloggs_variety_pak_512kb.mp4"}
})
canvas.Show()
while true
msg = Wait(0, port) ' where port is a roMessagePort
if type(msg) = "roVideoScreenEvent"
if msg.isScreenClosed()
end if
end if
end while

deviceInfo = CreateObject( "roDeviceInfo" )
displaySize = deviceInfo.GetDisplaySize()
background = {
Color: "#000000"
}
loadingImage = {
Url: "pkg:/images/Logo.png"
TargetRect: {
x: Int( displaySize.w / 2 ) - Int( 336 / 2 ),
y: Int( displaySize.h / 2 ) - Int( 209 / 2 ),
w: 365,
h: 110
}
}
loadingText = {
Text: "Loading...",
TextAttrs: {
Font: "Large",
VAlign: "Bottom"
},
TargetRect: {
x: loadingImage.TargetRect.x,
y: loadingImage.TargetRect.y + 225,
w: loadingImage.TargetRect.w,
h: 30
}
}
canvas = CreateObject( "roImageCanvas" )
canvas.SetLayer( 0, [ background, loadingImage, loadingText ] )
canvas.Show()

Main()

End Sub

Sub Main()

'initialize theme attributes like titles, logos and overhang color
initTheme()
screen=preShowHomeScreen("", "")
'set to go, time to get started
if screen=invalid then
print "unexpected error in preShowHomeScreen"
return
end if
showHomeScreen(screen)
End Sub


'*************************************************************
'** Set the configurable theme attributes for the application
'**
'** Configure the custom overhang and Logo attributes
'** Theme attributes affect the branding of the application
'** and are artwork, colors and offsets specific to the app
'*************************************************************

Sub initTheme()

app = CreateObject("roAppManager")
theme = CreateObject("roAssociativeArray")

theme.OverhangOffsetSD_X = "72"
theme.OverhangOffsetSD_Y = "31"
theme.OverhangSliceSD = "pkg:/images/Overhang_Background_SD.png"
theme.OverhangLogoSD = "pkg:/images/Overhang_Logo_SD.png"

theme.OverhangOffsetHD_X = "125"
theme.OverhangOffsetHD_Y = "35"
theme.OverhangSliceHD = "pkg:/images/Overhang_Background_HD.png"
theme.OverhangLogoHD = "pkg:/images/Overhang_Logo_HD.png"
theme.BackgroundColor = "#FFFFFF"
app.SetTheme(theme)

End Sub


Any experienced developers, I'd appreciate you help. Maybe RokuChris? Thanks.
0 Kudos
destruk
Streaming Star

Re: Pre Roll Screen?

You created the facade screen, but it was never shown() so it isn't actually open.
Add this after you create the facade screen.

screenFacade.Show()

Also, in your prior code listing, you use port but don't have it defined.
0 Kudos
belltown
Roku Guru

Re: Pre Roll Screen?

It's exiting the channel because you haven't defined "port" (among other reasons).

When you try and run this code you should see it enter the debugger, where it will tell you what the problem is.

You can find out more about using the debugger in the Developer Guide and the BrightScript Reference Manual. For example, if you run a telnet session to port 8085 on your Roku whenever you try to load and run a new channel, the debugger console will appear and show the debugging information. If it finds a syntax error or runtime error it will also tell you on what line in your code the error was encountered.
0 Kudos
RokuChris
Roku Employee
Roku Employee

Re: Pre Roll Screen?

I see that you have both a Main() and a RunUserInterface(). Those are both special function names designated as entry points. Having both will not necessarily break things, but as a matter of best practice each channel should only define one of them, never both.

Section 2.5 of the Component Reference talks about application entry points.
0 Kudos