Function Main()
InitTheme()
this = {
gridScreenPort: CreateObject("roMessagePort")
gridScreen: CreateObject("roGridScreen")
row: get_playlists_by_player_id()
row_items: get_playlists_row_by_player_id()
}
this.gridScreen.SetMessagePort(this.gridScreenPort)
this.gridScreen.setGridStyle("four-column-flat-landscape")
this.gridscreen.setDisplayMode("photo-fit")
rowTitles = CreateObject("roArray", 10, true)
for i = 0 to this.row.count() -1
rowTitles.push(this.row[i])
end for
row_items = CreateObject("roArray", 10, true)
for k = 0 to this.row_items.count() -1
row_items.push(this.row_items[k].title)
end for
this.gridScreen.SetupLists(rowTitles.Count())
this.gridScreen.SetListNames(row_items)
for j = 0 to this.row_items.count() -1
list = CreateObject("roArray", 10, true)
for i = 0 to get_playlist_videos(rowTitles[j].id).count() -1
----> Problem Area list.Push(get_playlist_videos(rowTitles[i]))
end for
this.gridScreen.SetContentList(j, list)
end for
this.gridScreen.Show()
while true
msg = wait(0, this.port)
if type(msg) = "roGridScreenEvent" then
if msg.isScreenClosed() then
return -1
elseif msg.isListItemFocused()
print "Focused msg: ";msg.GetMessage();"row: ";msg.GetIndex();
print " col: ";msg.GetData()
elseif msg.isListItemSelected()
print "Selected msg: ";msg.GetMessage();"row: ";msg.GetIndex();
print " col: ";msg.GetData()
endif
endif
end while
End Function
Function get_playlist_videos(id as String) as object
request = CreateObject("roUrlTransfer")
port = CreateObject("roMessagePort")
request.SetPort(port)
request.Addheader("x-roku-reserved-dev-id","")
request.SetCertificatesFile("pkg:/certs/bundle.crt")
request.InitClientCertificates()
request.SetUrl("https://blank.com/api/v1/playlists/" + id + "/videos.json" + "?order=created_at.desc&" + "token=" + config().api_Key)
if (request.AsyncGetToString())
while (true)
msg = wait(1000, port)
if (type(msg) = "roUrlEvent")
code = msg.GetResponseCode()
if (code = 200)
playlist_items = CreateObject("roArray", 10, true)
json = ParseJSON(msg.GetString())
for each item in json
items = {
ID: item.id
Title: item.title
ContentType: "episode"
Description: item.description
length: FIX(item.duration)
HDPosterUrl: item.image.thumb
SDPosterUrl: item.image.thumb
streamFormat: "mp4"
url: item.transcodings[0].http_uri
url: item.transcodings[1].http_uri
}
playlist_items.push(items)
print items
end for
return playlist_items
endif
endif
if (msg = invalid)
request.AsyncCancel()
endif
end while
endif
return invalid
End Function
for i = 0 to get_playlist_videos(rowTitles[j].id).count() -1You appear to be making a web request for videos based on the row id that you're looping through, but never using, then making a second web request inside that loop for videos based on a different item in the rowTitles array. On top of that, your call inside the loop is passing the rowTitles object, and not a string that the get_playlist_videos() function is expecting.
rowTitles = CreateObject("roArray", 10, true)
for i = 0 to this.row.count() -1
rowTitles.push(this.row[i])
end for
Function Main()
sleep(500)
InitTheme()
'Create Facade Screen
facade=createobject("roPosterScreen")
facade.show()
this = {
gridScreenPort: CreateObject("roMessagePort")
gridScreen: CreateObject("roGridScreen")
row: get_playlists_by_player_id()
}
this.gridScreen.SetMessagePort(this.gridScreenPort)
this.gridScreen.setGridStyle("four-column-flat-landscape")
this.gridscreen.setDisplayMode("photo-fit")
rowTitles = CreateObject("roArray", 10, true)
for i = 0 to this.row.count() -1
rowTitles.push(this.row.title)
end for
this.gridScreen.SetupLists(this.row.Count())
this.gridScreen.SetListNames(rowTitles)
for j = 0 to this.row.Count() -1
this.gridScreen.SetContentList(j, get_playlist_videos(this.row.id))
end for
this.gridScreen.Show()
while true
msg = wait(0, this.gridScreenPort)
if type(msg) = "roGridScreenEvent" then
if msg.isScreenClosed() then
return -1
elseif msg.isListItemFocused()
print "Focused msg: ";msg.GetMessage();"row: ";msg.GetIndex();" col: ";msg.GetData()
elseif msg.isListItemSelected()
row = msg.GetIndex()
col = msg.GetData()
---> PlayVideo(this.row[row].video[col])
endif
endif
end while
End Function
for j = 0 to this.row.Count() -1
this.row[j].video = get_playlist_videos(this.row[j].id)
this.gridScreen.SetContentList(j,this.row[j].video)
end for