"lumaflix" wrote:
Can you provide an example to implement pagination, there is no youtube example.
Sample code snippet will be helpful.
If you take a look at the showFeed.brs file in the videoplayer example, you'll see that they have the beginning of a pagination solution in parse_show_feed
'for now, don't process meta info about the feed size
if curShow.GetName() = "resultLength" or curShow.GetName() = "endIndex" then
goto skipitem
endif
What I did was have my web server return only 20 items at a time, with a maxIndex and endIndex item. (Both zero-based, so I'm comparing indices, not index and length).
if curShow.GetName() = "maxIndex" then
m.maxIndex = curShow.GetText()
print "maxIndex: " + m.maxIndex
goto skipitem
elseif curShow.GetName() = "endIndex" then
m.lastIndex = curShow.GetText()
print "lastIndex: " + m.lastIndex
goto skipitem
endif
Then, in the poster screen code event handler, I check for the isListItemFocused event, and if I'm close to the end of my currently fetched list (less than 6 away), I fetch some more.
else if msg.isListItemFocused() then
'pagination
m.curShow = msg.GetIndex()
' print "list item focused | current show = "; m.curShow
' print "list item focused | last = "; m.lastIndex
' print "list item focused | max = "; m.maxIndex
if (m.lastIndex > 0) then
if ((m.lastIndex < m.maxIndex) and ((m.lastIndex-m.curShow) < 6)) then
screen.ShowMessage("Fetching...")
m.lastIndex = m.lastIndex + 1
m.shows = getShowsForCategoryItem(category, m.curCategory, m.shows)
screen.SetContentList(m.shows)
screen.ClearMessage()
endif
endif
I changed a few of the functions to allow me to pass the current show list into the fetch routine, and the parse routine will accept the show list and append the newly fetched shows to it. You'll also need to pass the start index to your web server in the query string.
I'm passing the indices back from the fetch routine as member variables on the connection object. These end up as variables on the posterScreen object, m.lastIndex and m.maxIndex.
This solved the initial fetch and parse issue for me, and makes the whole thing alot faster. The refetches are fast enough that the "loading..." screen comes and goes almost too fast to see.
Next step is to remember where I am in a particular list, so when I go from one category to another, then back, I stay where I was in the list (rather than starting at 0 again). This will require an initial fetch index, and the ability to page down as well as up. Someday, after I get playback to stop crapping out after an hour...