This is my code. Make sure you the image files are the same as those in your folder.
' ********************************************************************
' ** Sample PlayVideo App
' ** Copyright (c) 2009 Roku Inc. All Rights Reserved.
' ********************************************************************
Sub Main(args As Dynamic)
'initialize theme attributes like titles, logos and overhang color
initTheme()
'has to live for the duration of the whole app to prevent flashing
'back to the roku home screen.
screenFacade = CreateObject("roPosterScreen")
screenFacade.show()
item = { ContentType:"episode"
SDPosterUrl:"file://pkg:/images/MainMenu_Icon_Center_HD.png"
HDPosterUrl:"file://pkg:/images/MainMenu_Icon_Center_HD.png"
IsHD:True
HDBranded:True
ShortDescriptionLine1:""
ShortDescriptionLine2:""
Description:""
Rating:"NR"
StarRating:"80"
Length:1972
Categories:["Technology","Talk"]
Title:" "
}
showSpringboardScreen(item)
'exit the app gently so that the screen doesn't flash to black
screenFacade.showMessage("")
sleep(25)
End Sub
'*************************************************************
'** Set the configurable theme attributes for the application
'**
'** Configure the custom overhang and Logo attributes
'*************************************************************
Sub initTheme()
app = CreateObject("roAppManager")
theme = CreateObject("roAssociativeArray")
theme.OverhangPrimaryLogoOffsetSD_X = "72"
theme.OverhangPrimaryLogoOffsetSD_Y = "15"
theme.OverhangSliceSD = "pkg:/images/Overhang_BackgroundSlice_SD43.png"
theme.OverhangPrimaryLogoSD = "pkg:/images/Logo_Overhang_SD43.png"
theme.OverhangPrimaryLogoOffsetHD_X = "123"
theme.OverhangPrimaryLogoOffsetHD_Y = "20"
theme.OverhangSliceHD = "pkg:/images/Overhang_BackgroundSlice_HD.png"
theme.OverhangPrimaryLogoHD = "pkg:/images/Logo_Overhang_HD.png"
app.SetTheme(theme)
End Sub
'*************************************************************
'** showSpringboardScreen()
'*************************************************************
Function showSpringboardScreen(item as object) As Boolean
port = CreateObject("roMessagePort")
screen = CreateObject("roSpringboardScreen")
print "showSpringboardScreen"
screen.SetMessagePort(port)
screen.AllowUpdates(false)
if item <> invalid and type(item) = "roAssociativeArray"
screen.SetContent(item)
endif
screen.SetDescriptionStyle("generic") 'audio, movie, video, generic
' generic+episode=4x3,
screen.ClearButtons()
screen.AddButton(1,"Play")
screen.AddButton(2,"Go Back")
screen.SetStaticRatingEnabled(false)
screen.AllowUpdates(true)
screen.Show()
downKey=3
selectKey=6
while true
msg = wait(0, screen.GetMessagePort())
if type(msg) = "roSpringboardScreenEvent"
if msg.isScreenClosed()
print "Screen closed"
exit while
else if msg.isButtonPressed()
print "Button pressed: "; msg.GetIndex(); " " msg.GetData()
if msg.GetIndex() = 1
displayVideo("")
else if msg.GetIndex() = 2
return true
endif
else
print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
endif
else
print "wrong type.... type=";msg.GetType(); " msg: "; msg.GetMessage()
endif
end while
return true
End Function
'*************************************************************
'** displayVideo()
'*************************************************************
Function displayVideo(args As Dynamic)
print "Displaying video: "
p = CreateObject("roMessagePort")
video = CreateObject("roVideoScreen")
video.setMessagePort(p)
bitrates = [0] ' 0 = no dots, adaptive bitrate
'bitrates = [348] ' <500 Kbps = 1 dot
'bitrates = [664] ' <800 Kbps = 2 dots
'bitrates = [996] ' <1.1Mbps = 3 dots
'bitrates = [2048] ' >=1.1Mbps = 4 dots
'video
url = "http://www.youtube.com/watch?v=RfOSqpZ0jEM&feature=youtube_gdata" ' The URL for the video
mp4Urls = getMP4Url (url) ' Get a list of all MP4 URLs
sdUrl = mp4Urls.sdUrl
hdUrl = mp4Urls.hdUrl ' Will be empty string if no HD MP4 found
hd1080pUrl = mp4Urls.hd1080pUrl ' Will be empty string if no 1080p MP4 found
urls = [sdUrl]
qualities = ["SD"]
StreamFormat = "mp4"
title = "Youtube"
if type(args) = "roAssociativeArray"
if type(args.url) = "roString" and args.url <> "" then
urls[0] = args.url
end if
if type(args.StreamFormat) = "roString" and args.StreamFormat <> "" then
StreamFormat = args.StreamFormat
end if
if type(args.title) = "roString" and args.title <> "" then
title = args.title
else
title = ""
end if
end if
videoclip = CreateObject("roAssociativeArray")
videoclip.StreamBitrates = bitrates
videoclip.StreamUrls = urls
videoclip.StreamQualities = qualities
videoclip.StreamFormat = StreamFormat
videoclip.Title = title
video.SetContent(videoclip)
video.show()
lastSavedPos = 0
statusInterval = 10 'position must change by more than this number of seconds before saving
while true
msg = wait(0, video.GetMessagePort())
if type(msg) = "roVideoScreenEvent"
if msg.isScreenClosed() then 'ScreenClosed event
print "Closing video screen"
exit while
else if msg.isPlaybackPosition() then
nowpos = msg.GetIndex()
if nowpos > 10000
end if
if nowpos > 0
if abs(nowpos - lastSavedPos) > statusInterval
lastSavedPos = nowpos
end if
end if
else if msg.isRequestFailed()
print "play failed: "; msg.GetMessage()
else
print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
endif
end if
end while
End Function
function getMP4Url (urlParam as string) as object
mp4VideoList = {sdUrl: "", hdUrl: "", hd1080pUrl: ""}
urlTransferObject = CreateObject ("roUrlTransfer")
urlTransferObject.SetPort (CreateObject ("roMessagePort"))
urlTransferObject.SetUrl (urlParam)
htmlString = urlTransferObject.GetToString ()
urlEncodedFmtStreamMap = CreateObject ("roRegex", "url_encoded_fmt_stream_map=([^(" + Chr (34) + "|&|$)]*)", "").Match (htmlString)
if urlEncodedFmtStreamMap.Count () < 2 then return mp4VideoList
urlEncodedFmtStreamList = CreateObject ("roRegex", "%2C", "").Split (urlEncodedFmtStreamMap [1])
for each urlEncodedFmtStream in urlEncodedFmtStreamList
urlStreamMatches = CreateObject ("roRegex", "url%3D(http.*?)%26", "").Match (urlEncodedFmtStream)
if urlStreamMatches.Count () > 1
urlDecoded = CreateObject ("roUrlTransfer").Unescape (CreateObject ("roUrlTransfer").Unescape (urlStreamMatches [1]))
if CreateObject ("roRegex", "itag=18\D", "").IsMatch (urlDecoded)
mp4VideoList.sdUrl = urlDecoded
else if CreateObject ("roRegex", "itag=22\D", "").IsMatch (urlDecoded)
mp4VideoList.hdUrl = urlDecoded
else if CreateObject ("roRegex", "itag=37\D", "").IsMatch (urlDecoded)
mp4VideoList.hd1080pUrl = urlDecoded
endif
endif
end for
return mp4VideoList
end function