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

Issue with gridscreen

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
0 Kudos
4 REPLIES 4
TheEndless
Channel Surfer

Re: Issue with gridscreen

The first problem I see is that you don't have a facade screen to keep the channel alive while you're retrieving the content, so it's probably closing the channel automatically before it gets far enough to display anything.

The second problem I see is this line:
for i = 0 to get_playlist_videos(rowTitles[j].id).count() -1
You 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.

And finally, but likely unrelated to your issue... what's the purpose in this loop?
    rowTitles = CreateObject("roArray", 10, true)
for i = 0 to this.row.count() -1
rowTitles.push(this.row[i])
end for

Why copy "this.row" into a brand new array?
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
uarlive
Visitor

Re: Issue with gridscreen

Thanks for your help TheEndless. I have resolved the three mentioned issues. The last portion that is giving me trouble is the eventloop.


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
0 Kudos
TheEndless
Channel Surfer

Re: Issue with gridscreen

With the limited information I can glean from the code, my guess is that "this.row[row]" doesn't actually contain a "video" attribute, since you're making a separate request for those videos when you populate the grid screen. You probably need to add it in your SetContentList loop. Something like:
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
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
uarlive
Visitor

Re: Issue with gridscreen

That did it! Thanks again.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.