jsonAsString = CreateObject("roUrlTransfer")
jsonAsString.SetURL(URL()+"/movie.php?cat="+HttpEncode(category))
json = ParseJson(jsonAsString.GetToString())
return json.Videos
Sub showMoviesScreen()
dlg = CreateObject("roOneLineDialog")
dlg.setTitle("Loading Collection")
dlg.showBusyAnimation()
dlg.show()
screen = CreateObject("roGridScreen")
port = CreateObject("roMessagePort")
screen.SetMessagePort(port)
screen.SetGridStyle("flat-portrait")
screen.SetDescriptionVisible(true)
screen.SetBreadcrumbText("Movies", "Session")
categoryList = getCategoryListMovies()
categoryCount = categoryList.count()
seriesList = CreateObject("roList")
screen.SetupLists(categoryCount)
screen.ClearMessage()
screen.show()
screen.setListNames(categoryList)
for i = 0 to categoryCount-1
print "id = "; i; " categoria = "; categoryList[i]
contentList = getMoviesByCategory(categoryList[i])
seriesList[i] = contentList
screen.SetContentList(i,contentList)
screen.ClearMessage()
end for
screen.ClearMessage()
screen.show()
dlg.close()
clock = CreateObject("roTimespan")
next_call = clock.TotalMilliseconds() + 36000
while (true)
msg = wait(250, port)
if msg <> invalid and type(msg) = "roGridScreenEvent" then
if msg.isScreenClosed() then
exit while
else if msg.isStatusMessage()
mensaje = msg.getMessage()
status = msg.GetIndex()
else if msg.isPlaybackPosition()
nowpos = msg.GetIndex()
print "Tiempo conectado: "; nowpos
else if msg.isListItemFocused()
print "Focused msg: ";msg.GetMessage();"row: ";msg.GetIndex();
print " col: ";msg.GetData()
else if msg.isListItemSelected()
print "Selected msg: ";msg.GetMessage();"row: ";msg.GetIndex();
'selection = seriesList.GetEntry(msg.GetIndex())[msg.GetData()]
row = msg.GetIndex()
col = msg.GetData()
list = seriesList.GetEntry(msg.GetIndex())
if list <> invalid then
selection = list[msg.GetData()]
end if
if (row=0 and col=0) then
searchMovies()
else if (row=0 and col=1) then
FavoritesMovies()
else
'showSpringboardScreenMovies(list,selection)
showSpringboardScreenMovies(list,msg.GetData())
end if
else
print "Unexpected msg type: "; msg.GetType()
print "mensaje: "; msg.getMessage()
end if
end if
if clock.TotalMilliseconds() > next_call then
next_call = clock.TotalMilliseconds() + 36000
end if
end while
End Sub
Function getCategoryListMovies() as object
http = NewHTTP(ServidorRoku()+"/categorias.json")
http.AddParam("t", "peliculas")
response= http.GetToStringWithTimeout(90)
json = ParseJSON(response)
return json
End Function
Function getMoviesByCategory(category)
http = NewHTTP(ServidorRoku()+"/movie.json")
http.AddParam("cat", category)
response= http.GetToStringWithTimeout(90)
json = ParseJSON(response)
return json.Videos
End Function
"TheEndless" wrote:
To make the API requests asynchronously, you'll basically need to use ifUrlTransfer.AsyncGetToString(), then listen for roUrlEvents in your event loop. Once you get the result back, you can then set the contents for the grid screen row(s).
Alternatively, you could opt to work with SceneGraph instead, and utilize the Task node for retrieving your content.