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

VideoScreen Issue with Parsing JSON

I am trying to load the content of a JSON response into the ShowVideoScreen function and play video. I have modified the webservices sdk template to query my api and return a response. Any help in the right direction is appreciated.

JSON.brs
Function get_playlist_videos(id as String) as object
request = CreateObject("roUrlTransfer")
port = CreateObject("roMessagePort")
request.SetMessagePort(port)
request.Addheader("x-roku-reserved-dev-id","")
request.SetCertificatesFile("pkg:/certs/server.crt")
request.InitClientCertificates()
request.SetUrl("https://1234.com/api/v1/playlists/" + id + "/videos.json?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
Synopsis: item.description
Length: item.duration / 1000
ShortDescriptionLine1: item.title
HDPosterUrl: item.image.thumb
SDPosterUrl: item.image.thumb
streamFormat: "mp4"
HDstreamUrl: item.transcodings[1].http_uri
SDstreamUrl: item.transcodings[2].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


Screen.brs
Function ShowPosterScreen(title as String, playlist_items_array as object) as integer
this = {
posterScreen: CreateObject("roPosterScreen")
posterScreenPort: CreateObject("roMessagePort")
playlist_items: playlist_items_array
}
this.posterScreen.SetMessagePort(this.posterScreenPort)
this.posterScreen.SetBreadcrumbText(title, "")
this.posterScreen.SetContentList(this.playlist_items)
this.posterScreen.SetListStyle( "flat-category" )
this.posterScreen.Show()

while(true)
msg = wait(0,this.posterScreenPort)
if (type(msg) = "roPosterScreenEvent")
if (msg.IsListItemSelected())
ShowSpringboardScreen(this.playlist_items[msg.GetIndex()])
else if (msg.isScreenClosed()) then
return -1
end if
end if
end while

End Function



Function ShowSpringboardScreen(Episode as object)
screen = CreateObject("roSpringboardScreen")
screen.SetMessagePort(CreateObject("roMessagePort"))
screen.SetStaticRatingEnabled(false)
screen.AddButton(1, "Play")
screen.Show()

screen.SetContent(Episode)
screen.Show()

while true
msg = wait(0, screen.GetMessagePort())

if msg <> invalid
if msg.isScreenClosed()
exit while
else if msg.isButtonPressed()
ShowVideoScreen(Episode)
end if
end if
end while

return Episode
End Function



Video.brs
Function ShowVideoScreen(title as String, video_array as object) as integer
this = {
videoScreen: CreateObject("roPosterScreen")
videoScreenPort: CreateObject("roMessagePort")
videos: video_array
}
this.videoScreen.SetMessagePort(this.videoScreenPort)
this.videoScreen.SetBreadcrumbText(title, "")
this.videoScreen.SetContentList(this.videos)
this.videoScreen.Show()

while(true)
msg = wait(0,this.videoScreenPort)
if (type(msg) = "roVideoScreenEvent")
if (msg.IsListItemSelected())
print this.videos[msg.GetIndex()]
PlayVideo(this.videos[msg.GetIndex()])
else if (msg.isScreenClosed()) then
return -1
end if
end if
end while

End Function

Function PlayVideo(video as object) as integer
videoScreen = CreateObject("roVideoScreen")
port = CreateObject("roMessagePort")
videoScreen.SetMessagePort( port )

metaData = {
ContentType: "episode",
Title: video.Title,
Description: video.Title,
Stream: {
Url: video.Url
}
StreamFormat: "hls"
}
videoScreen.SetContent( metaData )
videoScreen.show()

while (true)
msg = wait(0, port)
if type(msg) = "roVideoScreenEvent"
if (msg.isScreenClosed())
return -1
end if
endif
end while


End Function
0 Kudos
3 REPLIES 3
joetesta
Roku Guru

Re: VideoScreen Issue with Parsing JSON

are you connected to your roku debugger with telnet to port 8085 ? That will give you a bunch of info to help determine what's wrong, most importantly the error and line number that triggered it.
aspiring
0 Kudos
uarlive
Visitor

Re: VideoScreen Issue with Parsing JSON

Thanks Joetesta here is the error.

BrightScript Micro Debugger.
Enter any BrightScript statement, debug commands, or HELP.

Current Function:
028: Function ShowSpringboardScreen(Episode as object)
029: screen = CreateObject("roSpringboardScreen")
030: screen.SetMessagePort(CreateObject("roMessagePort"))
031: screen.SetStaticRatingEnabled(false)
032: screen.AddButton(1, "Play")
033: screen.Show()
034:
035: screen.SetContent(Episode)
036: screen.Show()
037:
038: while true
039: msg = wait(0, screen.GetMessagePort())
040:
041: if msg <> invalid
042: if msg.isScreenClosed()
043: exit while
044: else if msg.isButtonPressed()
045: ShowVideoScreen(Episode)
046: end if
047: end if
048: end while
049:
050: return Episode
051: End Function
Wrong number of function parameters. (runtime error &hf1) in ...8yAQQ/pkg:/source/Screens.brs(45)

045: ShowVideoScreen(Episode)
Backtrace:
Function showspringboardscreen(episode As <uninitialized>) As
file/line: /tmp/plugin/LMAA...8yAQQ/pkg:/source/Screens.brs(45)
Function showposterscreen(title As , playlist_items_array As <uninitialized>) As Integer
file/line: /tmp/plugin/LMAA...8yAQQ/pkg:/source/Screens.brs(17)
Function main() As
file/line: /tmp/plugin/LMAAAA78yAQQ/pkg:/source/appMain.brs(18)

Local Variables:
episode &h4010 bsc:roAssociativeArray, refcnt=2
global &h0020 rotINTERFACE:ifGlobal
m &h0010 bsc:roAssociativeArray, refcnt=4
screen &h0010 bsc:roSpringboardScreen, refcnt=1
msg &h0010 bsc:roSpringboardScreenEvent, refcnt=1
BrightScript Debugger> Syntax Error. (compile error &h02) in $LIVECOMPILE(54)

BrightScript Debugger> Syntax Error. (compile error &h02) in $LIVECOMPILE(55)

BrightScript Debugger> Syntax Error. (compile error &h02) in $LIVECOMPILE(55)

BrightScript Debugger> Syntax Error. (compile error &h02) in $LIVECOMPILE(55)

BrightScript Debugger> Syntax Error. (compile error &h02) in $LIVECOMPILE(55)

BrightScript Debugger> Syntax Error. (compile error &h02) in $LIVECOMPILE(56)

BrightScript Debugger> Syntax Error. (compile error &h02) in $LIVECOMPILE(56)

BrightScript Debugger> Syntax Error. (compile error &h02) in $LIVECOMPILE(57)

BrightScript Debugger> BrightScript Debugger> BrightScript Debugger> BrightScript Debugger> BrightScript Debugger> BrightScript Debugger> BrightScript Debugger> BrightScript Debugger>
0 Kudos
uarlive
Visitor

Re: VideoScreen Issue with Parsing JSON

I figured it out. I removed the call to ShowVideoScreen and set the ShowSpringboard to call PlayVideo.
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.