I'm getting back to wok on the pre-roll again after working on different parts of the channel. Trying to see what step one is to making the pre-roll work. Going to take time to back track and start from scratch to see if this code will work for me. I haven't had time to work on the pre-roll recently until now.
destruk, the code you provided, I should put this into it's own brs file, is this correct?
' *********************************************************
' ** Simple Poster Screen Demonstration App
' ** Nov 2009
' ** Copyright (c) 2009 Roku Inc. All Rights Reserved.
' *********************************************************
'************************************************************
'** Application startup
'************************************************************
Sub Main()
'initialize theme attributes like titles, logos and overhang color
initTheme()
'prepare the screen for display and get ready to begin
screen=preShowPosterScreen("", "")
if screen=invalid then
print "unexpected error in preShowPosterScreen"
return
end if
'set to go, time to get started
showPosterScreen(screen)
End Sub
'*************************************************************
'** Set the configurable theme attributes for the application
'**
'** Configure the custom overhang and Logo attributes
'** These 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 = "25"
theme.OverhangSliceSD = "pkg:/images/Overhang_BackgroundSlice_Blue_SD43.png"
theme.OverhangLogoSD = "pkg:/images/Logo_Overhang_Roku_SDK_SD43.png"
theme.OverhangOffsetHD_X = "123"
theme.OverhangOffsetHD_Y = "48"
theme.OverhangSliceHD = "pkg:/images/Overhang_BackgroundSlice_Blue_HD.png"
theme.OverhangLogoHD = "pkg:/images/Logo_Overhang_Roku_SDK_HD.png"
app.SetTheme(theme)
End Sub
'******************************************************
'** Perform any startup/initialization stuff prior to
'** initially showing the screen.
'******************************************************
Function preShowPosterScreen(breadA=invalid, breadB=invalid) As Object
port=CreateObject("roMessagePort")
screen = CreateObject("roPosterScreen")
screen.SetMessagePort(port)
if breadA<>invalid and breadB<>invalid then
screen.SetBreadcrumbText(breadA, breadB)
end if
screen.SetListStyle("arced-landscape")
return screen
End Function
'******************************************************
'** Display the poster screen and wait for events from
'** the screen. The screen will show retreiving while
'** we fetch and parse the feeds for the show posters
'******************************************************
Function showPosterScreen(screen As Object) As Integer
'SET UP PREROLL CONTENT
preroll={streamFormat: "mp4",stream: {url: "http://www.archive.org/download/kelloggs_variety_pak/kelloggs_variety_pak_512kb.mp4"}} 'added for preroll
'alternately you can parse your xml data here
'prerollseries=InitAdFeedConnection() 'load xml for preroll videos
'preroll=prerollseries[0] 'set preroll video to first advertisement in ad xml feed library
'END OF PREROLL CONTENT
categoryList = getCategoryList()
screen.SetListNames(categoryList)
iSelected=0
CurrentContent=getShowsForCategoryItem(categoryList[0])
screen.SetContentList(CurrentContent)
screen.Show()
while true
msg = wait(0, screen.GetMessagePort())
if type(msg) = "roPosterScreenEvent" then
print "showPosterScreen | msg = "; msg.GetMessage() " | index = "; msg.GetIndex()
if msg.isListFocused() then
'get the list of shows for the currently selected item
iSelected=0
CurrentContent=getShowsForCategoryItem(categoryList[msg.GetIndex()])
screen.SetContentList(CurrentContent)
print "list focused | current category = "; msg.GetIndex()
else if msg.isListItemFocused() then
print"list item focused | current show = "; msg.GetIndex()
iSelected=msg.GetIndex()
else if msg.isListItemSelected() then
'INSERTED PREROLL CODE
' create and display a blank roImageCanvas to prevent the
' underlying UI from flickering between videos
CanvasBlock=CreateObject("roImageCanvas")
CanvasBlock.SetLayer(0,"#000000")
CanvasBlock.Show()
' play the preroll video with trick play disabled
If ShowPreroll(preroll)
' only play the main content if the preroll completed without user intervention
PlayVideo(CurrentContent[iSelected])
End If
' close the blank canvas and return the user to the previous UI screen
CanvasBlock.Close()
'END OF PREROLL CODE INSERTION
else if msg.isScreenClosed() then
return -1
end if
end If
end while
End Function
'PREROLL FUNCTION
Function ShowPreRoll(video) As Boolean
' 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
CanvasPreroll=CreateObject("roImageCanvas")
PlayerPreRoll=CreateObject("roVideoPlayer")
Port=CreateObject("roMessagePort")
CanvasPreroll.SetMessagePort(Port)
' build a very simple buffer screen for our preroll video
CanvasPreroll.SetLayer(0, { text: "Your program will begin after this message" })
CanvasPreroll.Show()
' be sure to use the same message port for both the canvas and the player
' so we can receive events from both
PlayerPreRoll.SetMessagePort(Port)
PlayerPreRoll.SetDestinationRect(CanvasPreroll.GetCanvasRect())
PlayerPreRoll.AddContent(video)
PlayerPreRoll.Play()
' start our event loop
While True
' wait for an event
msg=Wait(0, CanvasPreroll.GetMessagePort())
If Type(msg)="roVideoPlayerEvent"
If msg.isFullResult()
' the video played to the end without user intervention
Exit While
Else If msg.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
CanvasPreroll.SetLayer(0, { color: "#00000000", CompositionMode: "Source" })
CanvasPreroll.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
PlayerPreRoll.Stop()
CanvasPreroll.Close()
Return Result
End Function
'END OF PREROLL FUNCTION
'***** VIDEO PLAYBACK *****
'This will only work if you have valid streaming show data
Function PlayVideo(CurrentVideo As Object)
port=CreateObject("roMessagePort")
screen=CreateObject("roVideoScreen")
screen.SetMessagePort(port)
screen.SetContent(CurrentVideo)
screen.Show()
While TRUE
msg=Wait(0,port)
If Type(msg)="roVideoScreenEvent"
'Print"showHomeScreen | msg = ";msg.getMessage();" | index = ";msg.GetIndex()
If msg.isScreenClosed()
' Print"Screen closed"
Exit While
Else If msg.isRequestFailed()
Print"Video request failure: ";msg.GetIndex();" ";msg.GetMessage()
Else If msg.isStatusMessage()
Print"Video status: ";msg.GetIndex();" ";msg.GetData()
If msg.GetIndex()=0 And msg.GetData()=0
print "Error With encode, we assume it played the full video"
Exit While
End If
Else If msg.isButtonPressed()
Print"Button pressed: ";msg.GetIndex();" ";msg.GetData()
Else If msg.isFullResult() 'played full video
print "Full Result"
Exit While
Else If msg.isPartialResult()
print "Partial Result"
Exit While
Else
Print"Unexpected event type: ";msg.GetType()
End If
Else
Print"Unexpected message class: ";Type(msg)
End If
End While
End Function
'**************************************************************
'** Return the list of categories to display in the filter
'** banner. The result is an roArray containing the names of
'** all of the categories. All just static data for the example.
'***************************************************************
Function getCategoryList() As Object
categoryList = CreateObject("roArray", 10, true)
categoryList = [ "Comedy", "Drama", "News", "Reality", "Daytime" ]
return categoryList
End Function
'********************************************************************
'** Given the category from the filter banner, return an array
'** of ContentMetaData objects (roAssociativeArray's) representing
'** the shows for the category. For this example, we just cheat and
'** create and return a static array with just the minimal items
'** set, but ideally, you'd go to a feed service, fetch and parse
'** this data dynamically, so content for each category is dynamic
'********************************************************************
Function getShowsForCategoryItem(category As Object) As Object
print "getting shows for category "; category
showList = [
{
ShortDescriptionLine1:"Show #1",
ShortDescriptionLine2:"Short Description for Show #1",
}
{
ShortDescriptionLine1:"Show #2",
ShortDescriptionLine2:"Short Description for Show #2",
HDPosterUrl:"pkg:/media/bogusFileName_hd.jpg",
SDPosterUrl:"pkg:/media/bogusFileName_hd.jpg"
}
{
ShortDescriptionLine1:"Show #3",
ShortDescriptionLine2:"Short Description for Show #3",
}
]
return showList
End Function
http://www.victoryNOWfilmsandtv.com