Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
kooljay68
Level 7

Will This Work ???

in the showFeeds.brs I created:


item.cost = strtoi(item.cost)
item.modelId = strtoi(item.modelId)

m.cost = item.cost
m.model = item.modelId


then on the appDetailScreen.brs I am trying to do the following: but does not seem to be quite right yet ? Any ideas?


else if msg.isButtonPressed()
print "ButtonPressed"
print "ButtonPressed"
if msg.GetIndex() = 1

if m.cost = 25 then
funds = tokenValidation()
if funds = 1 then
exit while
else
chargeCustomer()
end if
end if

PlayStart = RegRead(showList[showIndex].ContentId)
if PlayStart <> invalid then
showList[showIndex].PlayStart = PlayStart.ToInt()
endif



Function tokenValidation() As Integer
sn = GetDeviceESN()
xfer = CreateObject("roURLTransfer")
xfer.SetURL("http://allbabestv.com/mcams/roku/getCredits.php?deviceID=" + sn)
response = xfer.GetToString()
xml = CreateObject("roXMLElement")
if xml.Parse(response)
if (strtoi(xml.tokens) > item.cost)
return 0
end if
end if
return 1
end Function


Function chargeCustomer()
sn = GetDeviceESN()
xfer = CreateObject("roURLTransfer")
xfer.SetURL("http://allbabestv.com/mcams/roku/chargeCustomer.php?deviceID=" + sn + "&cost=" + m.cost + "&model=" + m.model)
response = xfer.GetToString()
end Function


Thanks for the help all
0 Kudos
10 REPLIES 10\
destruk
Level 10

Re: Will This Work ???

In showfeed.brs you have changed item.cost from a string to an integer with item.cost = strtoi(item.cost)
Then you set it global with m.cost = item.cost

Then in ChargeCustomer you're using it as an integer from the global reference m.cost

m.cost needs to be a string to be used in a string url

xfer.SetURL("http://allbabestv.com/mcams/roku/chargeCustomer.php?deviceID=" + sn + "&cost=" + m.cost.tostr() + "&model=" + m.model)

what errors do you get when you try to run it?
0 Kudos
kooljay68
Level 7

Re: Will This Work ???

It doesn't seem to be doing the token validation ?

It is just letting it play?


if m.cost = 25 then
funds = tokenValidation()
if funds = 0 then
exit while
else
chargeCustomer()
end if
end if
0 Kudos
kooljay68
Level 7

Re: Will This Work ???

it does not seem like the m.cost value is making it to the page ??
0 Kudos
RokuJoel
Roku Employee
Roku Employee

Re: Will This Work ???

If you post the whole video playback function then perhaps we can begin to understand the issue you are encountering and why.

FYI, you should sanitize your URLs unless you want random people to experiment with your server.

- Joel
0 Kudos
kooljay68
Level 7

Re: Will This Work ???

ok ... here is the appDetailScreen.brs



'**********************************************************
'** Video Player Example Application - Detail Screen
'** November 2009
'** Copyright (c) 2009 Roku Inc. All Rights Reserved.
'**********************************************************

Function preShowDetailScreen(breadA=invalid, breadB=invalid) As Object
port=CreateObject("roMessagePort")
screen = CreateObject("roSpringboardScreen")
screen.SetDescriptionStyle("video")
screen.SetMessagePort(port)
if breadA<>invalid and breadB<>invalid then
screen.SetBreadcrumbText(breadA, breadB)
end if

return screen
End Function

'***************************************************************
'** The show detail screen (springboard) is where the user sees
'** the details for a show and is allowed to select a show to
'** begin playback. This is the main event loop for that screen
'** and where we spend our time waiting until the user presses a
'** button and then we decide how best to handle the event.
'***************************************************************
Function showDetailScreen(screen As Object, showList As Object, showIndex as Integer) As Integer

if validateParam(screen, "roSpringboardScreen", "showDetailScreen") = false return -1
if validateParam(showList, "roArray", "showDetailScreen") = false return -1

refreshShowDetail(screen, showList, showIndex)

'remote key id's for left/right navigation
remoteKeyLeft = 4
remoteKeyRight = 5

while true
msg = wait(0, screen.GetMessagePort())

if type(msg) = "roSpringboardScreenEvent" then
if msg.isScreenClosed()
print "Screen closed"
exit while
else if msg.isRemoteKeyPressed()
print "Remote key pressed"
if msg.GetIndex() = remoteKeyLeft then
showIndex = getPrevShow(showList, showIndex)
if showIndex <> -1
refreshShowDetail(screen, showList, showIndex)
end if
else if msg.GetIndex() = remoteKeyRight
showIndex = getNextShow(showList, showIndex)
if showIndex <> -1
refreshShowDetail(screen, showList, showIndex)
end if
endif
else if msg.isButtonPressed()
print "ButtonPressed"
print "ButtonPressed"
if msg.GetIndex() = 1
PlayStart = RegRead(showList[showIndex].ContentId)
if PlayStart <> invalid then
showList[showIndex].PlayStart = PlayStart.ToInt()
endif
showVideoScreen(showList[showIndex])
endif
if msg.GetIndex() = 2
if m.cost = 0 then
showList[showIndex].PlayStart = 0
showVideoScreen(showList[showIndex])

else if m.cost = 999 then
showList[showIndex].PlayStart = 0
showVideoScreen(showList[showIndex])

else if m.cost = 25 then
funds = tokenValidation()
if funds = 0 then
exit while
else
chargeCustomer()
showList[showIndex].PlayStart = 0
showVideoScreen(showList[showIndex])
end if
else if m.cost = 45 then
funds = tokenValidation()
if funds = 0 then
exit while
else
chargeCustomer()
showList[showIndex].PlayStart = 0
showVideoScreen(showList[showIndex])
end if
else if m.cost = 65 then
funds = tokenValidation()
if funds = 0 then
exit while
else
chargeCustomer()
showList[showIndex].PlayStart = 0
showVideoScreen(showList[showIndex])
end if
else if m.cost = 100 then
funds = tokenValidation()
if funds = 0 then
exit while
else
chargeCustomer()
showList[showIndex].PlayStart = 0
showVideoScreen(showList[showIndex])
end if
end if
endif
if msg.GetIndex() = 3
endif
print "Button pressed: "; msg.GetIndex(); " " msg.GetData()
end if
else
print "Unexpected message class: "; type(msg)
end if
end while

return showIndex

End Function

'**************************************************************
'** Refresh the contents of the show detail screen. This may be
'** required on initial entry to the screen or as the user moves
'** left/right on the springboard. When the user is on the
'** springboard, we generally let them press left/right arrow keys
'** to navigate to the previous/next show in a circular manner.
'** When leaving the screen, the should be positioned on the
'** corresponding item in the poster screen matching the current show
'**************************************************************
Function refreshShowDetail(screen As Object, showList As Object, showIndex as Integer) As Integer

if validateParam(screen, "roSpringboardScreen", "refreshShowDetail") = false return -1
if validateParam(showList, "roArray", "refreshShowDetail") = false return -1

show = showList[showIndex]

'Uncomment this statement to dump the details for each show
'PrintAA(show)

screen.ClearButtons()
'screen.AddButton(1, "Resume")
screen.AddButton(2, "Play Live")
screen.SetContent(show)
screen.Show()

End Function

'********************************************************
'** Get the next item in the list and handle the wrap
'** around case to implement a circular list for left/right
'** navigation on the springboard screen
'********************************************************
Function getNextShow(showList As Object, showIndex As Integer) As Integer
if validateParam(showList, "roArray", "getNextShow") = false return -1

nextIndex = showIndex + 1
if nextIndex >= showList.Count() or nextIndex < 0 then
nextIndex = 0
end if

show = showList[nextIndex]
if validateParam(show, "roAssociativeArray", "getNextShow") = false return -1

return nextIndex
End Function


'********************************************************
'** Get the previous item in the list and handle the wrap
'** around case to implement a circular list for left/right
'** navigation on the springboard screen
'********************************************************
Function getPrevShow(showList As Object, showIndex As Integer) As Integer
if validateParam(showList, "roArray", "getPrevShow") = false return -1

prevIndex = showIndex - 1
if prevIndex < 0 or prevIndex >= showList.Count() then
if showList.Count() > 0 then
prevIndex = showList.Count() - 1
else
return -1
end if
end if

show = showList[prevIndex]
if validateParam(show, "roAssociativeArray", "getPrevShow") = false return -1

return prevIndex
End Function

Function tokenValidation()
sn = GetDeviceESN()
xfer = CreateObject("roURLTransfer")
xfer.SetURL("http://myUrl/getCredits.php?deviceID=" + sn)
response = xfer.GetToString()
xml = CreateObject("roXMLElement")
if xml.Parse(response)
if (strtoi(xml.tokens) > m.cost)
return 0
end if
end if
return 1
end Function


Function chargeCustomer()
sn = GetDeviceESN()
xfer = CreateObject("roURLTransfer")
xfer.SetURL("http://myUrl/chargeCustomer.php?deviceID=" + sn + "&cost=" + m.cost.tostr() + "&model=" + m.model)
response = xfer.GetToString()
end Function
0 Kudos
kooljay68
Level 7

Re: Will This Work ???

and here is the entire showFeed.brs

**  Video Player Example Application - Show Feed 
'** November 2009
'** Copyright (c) 2009 Roku Inc. All Rights Reserved.
'**********************************************************

'******************************************************
'** Set up the show feed connection object
'** This feed provides the detailed list of shows for
'** each subcategory (categoryLeaf) in the category
'** category feed. Given a category leaf node for the
'** desired show list, we'll hit the url and get the
'** results.
'******************************************************

Function InitShowFeedConnection(category As Object) As Object

if validateParam(category, "roAssociativeArray", "initShowFeedConnection") = false return invalid

conn = CreateObject("roAssociativeArray")
conn.UrlShowFeed = category.feed

conn.Timer = CreateObject("roTimespan")

conn.LoadShowFeed = load_show_feed
conn.ParseShowFeed = parse_show_feed
conn.InitFeedItem = init_show_feed_item

print "created feed connection for " + conn.UrlShowFeed
return conn

End Function


'******************************************************
'Initialize a new feed object
'******************************************************
Function newShowFeed() As Object

o = CreateObject("roArray", 100, true)
return o

End Function


'***********************************************************
' Initialize a ShowFeedItem. This sets the default values
' for everything. The data in the actual feed is sometimes
' sparse, so these will be the default values unless they
' are overridden while parsing the actual game data
'***********************************************************
Function init_show_feed_item() As Object
o = CreateObject("roAssociativeArray")

o.ContentId = ""
o.Title = ""
o.ContentType = ""
o.ContentQuality = ""
o.Synopsis = ""
o.Genre = ""
o.Runtime = ""
o.StreamQualities = CreateObject("roArray", 5, true)
o.StreamBitrates = CreateObject("roArray", 5, true)
o.StreamUrls = CreateObject("roArray", 5, true)

return o
End Function


'*************************************************************
'** Grab and load a show detail feed. The url we are fetching
'** is specified as part of the category provided during
'** initialization. This feed provides a list of all shows
'** with details for the given category feed.
'*********************************************************
Function load_show_feed(conn As Object) As Dynamic

if validateParam(conn, "roAssociativeArray", "load_show_feed") = false return invalid

print "url: " + conn.UrlShowFeed
http = NewHttp(conn.UrlShowFeed)

m.Timer.Mark()
rsp = http.GetToStringWithRetry()
print "Request Time: " + itostr(m.Timer.TotalMilliseconds())

feed = newShowFeed()
xml=CreateObject("roXMLElement")
if not xml.Parse(rsp) then
print "Can't parse feed"
return feed
endif

if xml.GetName() <> "feed" then
print "no feed tag found"
return feed
endif

if islist(xml.GetBody()) = false then
print "no feed body found"
return feed
endif

m.Timer.Mark()
m.ParseShowFeed(xml, feed)
print "Show Feed Parse Took : " + itostr(m.Timer.TotalMilliseconds())

return feed

End Function


'**************************************************************************
'**************************************************************************
Function parse_show_feed(xml As Object, feed As Object) As Void

showCount = 0
showList = xml.GetChildElements()

for each curShow in showList

'for now, don't process meta info about the feed size
if curShow.GetName() = "resultLength" or curShow.GetName() = "endIndex" then
goto skipitem
endif

item = init_show_feed_item()

'fetch all values from the xml for the current show
item.hdImg = validstr(curShow@hdImg)
item.sdImg = validstr(curShow@sdImg)
item.ContentId = validstr(curShow.contentId.GetText())
item.cost = validstr(curShow.cost.GetText())
item.modelId = validstr(curShow.modelId.GetText())
item.Title = validstr(curShow.title.GetText())
item.Description = validstr(curShow.description.GetText())
item.ContentType = validstr(curShow.contentType.GetText())
item.ContentQuality = validstr(curShow.contentQuality.GetText())
item.Synopsis = validstr(curShow.synopsis.GetText())
item.Genre = validstr(curShow.genres.GetText())
item.Runtime = validstr(curShow.runtime.GetText())
item.HDBifUrl = validstr(curShow.hdBifUrl.GetText())
item.SDBifUrl = validstr(curShow.sdBifUrl.GetText())
item.StreamFormat = validstr(curShow.streamFormat.GetText())
if item.StreamFormat = "" then 'set default streamFormat to mp4 if doesn't exist in xml
item.StreamFormat = "mp4"
endif

'map xml attributes into screen specific variables
item.ShortDescriptionLine1 = item.Title
item.ShortDescriptionLine2 = item.Description
item.HDPosterUrl = item.hdImg
item.SDPosterUrl = item.sdImg

item.Length = strtoi(item.Runtime)
item.Categories = CreateObject("roArray", 5, true)
item.Categories.Push(item.Genre)
item.Actors = CreateObject("roArray", 5, true)
item.Actors.Push(item.Genre)
item.Description = item.Synopsis
item.cost = strtoi(item.cost)
item.modelId = strtoi(item.modelId)

m.cost = item.cost
m.model = item.modelId

'Set Default screen values for items not in feed
item.HDBranded = false
item.IsHD = false
item.StarRating = 90
item.ContentType = "episode"

if item.cost = 0 then
item.PlayDuration = 120

else if item.cost = 999 then
item.PlayDuration = 999

else if item.cost = 25 then
item.PlayDuration = 30

else if item.cost = 45 then
item.PlayDuration = 1230

else if item.cost = 65 then
item.PlayDuration = 1830

else if item.cost = 100 then
item.PlayDuration = 3630

end if

'media may be at multiple bitrates, so parse an build arrays
for idx = 0 to 4
e = curShow.media[idx]
if e <> invalid then
item.StreamBitrates.Push(strtoi(validstr(e.streamBitrate.GetText())))
item.StreamQualities.Push(validstr(e.streamQuality.GetText()))
item.StreamUrls.Push(validstr(e.streamUrl.GetText()))
endif
next idx

showCount = showCount + 1
feed.Push(item)

skipitem:

next

End Function

0 Kudos
RokuJoel
Roku Employee
Roku Employee

Re: Will This Work ???

None of those are your video playback function, which is in appVideoScreen.brs.

- Joel
0 Kudos
kooljay68
Level 7

Re: Will This Work ???

I have not modified it in anyway ?


'**********************************************************
'** Video Player Example Application - Video Playback
'** November 2009
'** Copyright (c) 2009 Roku Inc. All Rights Reserved.
'**********************************************************

'***********************************************************
'** Create and show the video screen. The video screen is
'** a special full screen video playback component. It
'** handles most of the keypresses automatically and our
'** job is primarily to make sure it has the correct data
'** at startup. We will receive event back on progress and
'** error conditions so it's important to monitor these to
'** understand what's going on, especially in the case of errors
'***********************************************************
Function showVideoScreen(episode As Object)

if type(episode) <> "roAssociativeArray" then
print "invalid data passed to showVideoScreen"
return -1
endif

port = CreateObject("roMessagePort")
screen = CreateObject("roVideoScreen")
screen.SetMessagePort(port)

screen.Show()
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
0 Kudos
kooljay68
Level 7

Re: Will This Work ???

ok .. so I pulled all the other stuff and put this code in and it still will not work .... can someone please tell me what I am doing wrong ... I cannot believe that this is really that hard to do ???



'**********************************************************
'** Video Player Example Application - Video Playback
'** November 2009
'** Copyright (c) 2009 Roku Inc. All Rights Reserved.
'**********************************************************

'***********************************************************
'** Create and show the video screen. The video screen is
'** a special full screen video playback component. It
'** handles most of the keypresses automatically and our
'** job is primarily to make sure it has the correct data
'** at startup. We will receive event back on progress and
'** error conditions so it's important to monitor these to
'** understand what's going on, especially in the case of errors
'***********************************************************
Function showVideoScreen(episode As Object)

if type(episode) <> "roAssociativeArray" then
print "invalid data passed to showVideoScreen"
return -1
endif

port = CreateObject("roMessagePort")
screen = CreateObject("roVideoScreen")
screen.SetMessagePort(port)

screen.Show()
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(100, port)

if m.cost = 25 then
funds = tokenValidation()
if funds = 1 then
exit while
else
chargeCustomer()
end if
end if

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


Function tokenValidation()
sn = GetDeviceESN()
xfer = CreateObject("roURLTransfer")
xfer.SetURL("http://allbabestv.com/mcams/roku/getCredits.php?deviceID=" + sn)
response = xfer.GetToString()
xml = CreateObject("roXMLElement")
if xml.Parse(response)
if (strtoi(xml.tokens) > m.cost)
return 0
end if
end if
return 1
end Function


Function chargeCustomer()
sn = GetDeviceESN()
xfer = CreateObject("roURLTransfer")
xfer.SetURL("http://allbabestv.com/mcams/roku/chargeCustomer.php?deviceID=" + sn + "&cost=" + m.cost + "&model=" + m.model)
response = xfer.GetToString()
end Function
0 Kudos