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

Delay Category Feed Load

I'm trying to modify the showPosterScreen() function from the video player sample in the SDK for my app.

One thing I've noticed is that Roku will fetch the feed for a focused category even when the user is only focusing on that category on his/her way to another category. For example, if the user moves from category 1 to category 6, Roku fetches the feeds for categories 2 through 5 before the content for category 6 is displayed. This has a big negative effect on my app's performance.

Is there an easy way to delay the fetching of a category feed without it affecting the responsiveness of the UI? Perhaps only fetch the category if the user remains focused on the category for a second or something?

Thanks!


Function showPosterScreen(screen As Object) As Integer

if validateParam(screen, "roPosterScreen", "showPosterScreen") = false return -1

m.curCategory = 0
m.curShow = 0

initCategoryList()
categoryList = getCategoryList(m.Categories)
screen.SetListNames(m.CategoryNames)
screen.SetContentList(getShowsForCategoryItem(categoryList[m.curCategory]))
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
m.curCategory = msg.GetIndex()
m.curShow = 0
'get the list of shows for the currently selected item
empty_list = CreateObject("roArray", 10, true)
screen.SetContentList(empty_list)
screen.ShowMessage("retrieving...")
screen.SetContentList(getShowsForCategoryItem(categoryList[msg.GetIndex()]))
screen.SetFocusedListItem(m.curShow)
print "list focused | current category = "; m.curCategory
else if msg.isListItemFocused() then
print "list item focused | current show = "; msg.GetIndex()
else if msg.isListItemSelected() then
m.curShow = msg.GetIndex()
print "list item selected | current show = "; m.curShow
m.curShow = displayShowDetailScreen(categoryList[m.curCategory], msg.GetIndex())
screen.setFocusedListItem(m.curShow)
else if msg.isScreenClosed() then
return -1
end if
end If
end while

End Function
0 Kudos
7 REPLIES 7
RokuChris
Roku Employee
Roku Employee

Re: Delay Category Feed Load

You probably want to move the content loading logic out of the isListFocused() handler and just set a flag there instead. Then, delay the content load till you're reasonably sure the user has stopped scrolling. viewtopic.php?f=34&t=35345
0 Kudos
sdornan
Visitor

Re: Delay Category Feed Load

Got it working. Thanks!
0 Kudos
ionatan
Roku Guru

Re: Delay Category Feed Load

How exactly you added this delay? Thanks
0 Kudos
RokuJoel
Binge Watcher

Re: Delay Category Feed Load

You can use rotimespan, executing mark() on each islistfocused() and loading content after timer.totalmilliseconds()>500 for example.

There are other approaches, I usually just cache all data in an array so that there is no need to go to the server every time the user changes categories. Usually I ignore the is listselected() event.

Joel
0 Kudos
ionatan
Roku Guru

Re: Delay Category Feed Load

Thanks, I will try rotimespan. I'm not sure how can be the content loaded after 500 ms, how can I make the script to wait, and just after 500 ms to load the content?!

Why are you ignoring islistselected()? By "I usually just cache all data in an array" you mean that you are saving the feed in tmp:/ ? Thanks
0 Kudos
RokuJoel
Binge Watcher

Re: Delay Category Feed Load

Here's a very rough outline of both caching and delaying category load:


function posterscreen()
screen=creatobject("roposterscreen")
screen.show()
screen.setlistnames(["zero","one","two","three","four"]]
'load all content for this screen into a cache variable:
MycontentarrayCache=getAndParseDataFromMyWebsite()
screen.setcontentlist(MyContentArrayCache[0])
timer=createobject("rotimespan")
timer.mark()
while true
msg=wait(1,port)
if type(msg)="roPosterScreenEvent" then
timer.mark() 'an event has happened, set a delay before loading data
if msg.islistfocused() and timer.totalmilliseconds() >500 then
ndx=msg.getindex()
screen.setcontentlist(MycontentarrayCache[ndx])
else if msg.islistselected()
ndx=msg.getindex()
'do nothing, although you *could* do a
'screen.setcontentlist here to override the timer, since this event
'indicates the user definitely wants to see this category
else if msg.islistitemfocused()
print "a list item is focused!"
else if msg.islistitemselected()
print "a list item is selected, do something"
end if
end while
end function


as far as caching goes, if you have five sections:

screen.setlistnames(["zero","one","two","three","four"]]

then you would need to load MycontentarrayCache[0] with an array containing each poster item for section zero, and MycontentarrayCache[1] with an array containing each poster item for section one, etc.

Hope that is helpful.

- Joel
0 Kudos
ionatan
Roku Guru

Re: Delay Category Feed Load

I tried this but timer return always 0

I found the issue. I changed this:

if type(msg)="roPosterScreenEvent" then
timer.mark() 'an event has happened, set a delay before loading data
if msg.islistfocused() and timer.totalmilliseconds() >500 then
ndx=msg.getindex()
screen.setcontentlist(MycontentarrayCache[ndx])
else if msg.islistselected()


In this


if type(msg)="roPosterScreenEvent" then
time_delay = timer.totalmilliseconds()
timer.mark() 'an event has happened, set a delay before loading data
if msg.islistfocused() and timer.time_delay >500 then
ndx=msg.getindex()
screen.setcontentlist(MycontentarrayCache[ndx])
else if msg.islistselected()
0 Kudos