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.brsFunction 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.brsFunction 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.brsFunction 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