I am having some trouble with getting the gridscreen to load content. The function get_playlist_videos() requires the playlist id to be passed as a string. I have tried to convert the integer to a string in the highlighted bold area. I have also tried adding a id.toStr() in the request. Any help is appreciated.
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
