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

Parsing Livestream events JSON

Hi,

I have tried to get the videos from live stream api and play the videos.but not working.How to fix it.

Below is the Code,i have used the sample live stream api link.


Function Main() as void

m.buttons = [
{Label: "Parse JSON", ID: 1}

]

port = CreateObject("roMessagePort")
screen = CreateObject("roParagraphScreen")
screen.SetMessagePort( port )

InitTheme()

screen.SetTitle("LiveStream JSON Parsing")
screen.AddHeaderText("Click the Parse JSON Button to read the JSON File")
screen.AddParagraph("Click the Parse JSON Button to read the JSON File")
for each button in m.buttons
screen.AddButton(button.ID, button.Label)
end for
screen.show()

while (true)
msg = wait(0, port)
if type( msg ) = "roParagraphScreenEvent"
if (msg.isButtonPressed())
HandleButtonPress(msg.GetIndex())
end if
end if
end while
End Function

Function InitTheme() as void
app = CreateObject("roAppManager")

theme = {
OverhangOffsetSD_X: "18"
OverhangOffsetSD_Y: "0"
OverhangSliceSD: "pkg:/images/Overhang_BackgroundSlice_SD.png"
OverhangLogoSD: "pkg:/images/json.png"
OverhangOffsetHD_X: "18"
OverhangOffsetHD_Y: "0"
OverhangSliceHD: "pkg:/images/Overhang_BackgroundSlice_HD.png"
OverhangLogoHD: "pkg:/images/json.png"
}
app.SetTheme(theme)

End Function

Function HandleButtonPress(id as integer) as void
LoadJSONFile()

End Function

Function LoadJSONFile() as void
'jsonAsString = ReadAsciiFile("http://new.livestream.com/api/accounts/4369605/events/2173796.json?callback=?")
xfer = CreateObject("roUrlTransfer")
xfer.SetUrl("http://new.livestream.com/api/accounts/4369605/events/2173796.json?callback=?")
jsonAsString = xfer.GetToString()
m.json = ParseJSON(jsonAsString)
ShowPosterScreen(m.json.feed)
End Function

Function ShowPosterScreen(feed as object) as integer
posterScreen = CreateObject("roPosterScreen")
port = CreateObject("roMessagePort")


posterScreen.SetMessagePort(port)
posterScreen.SetBreadcrumbText("LiveStream Playlist Result", "")
contentList = CreateObject("roArray", 2, true)
content=feed.data
for each i in content
poster = CreateObject("roAssociativeArray")
videourl = content[i].data.progressive_url
thumbnail_url = content[i].data.thumbnail_url
videotitle = content[i].data.caption
poster.ShortDescriptionLine1 = videotitle
poster.SDPosterURL = thumbnail_url
poster.HDPosterURL = thumbnail_url

contentList.push( poster )
end for
posterScreen.SetContentList( contentList )
posterScreen.SetFocusedListItem(2)
posterScreen.show()

while (true)
msg = wait(0, port)
if type(msg) = "roPosterScreenEvent"
if (msg.isListItemSelected())
PlayVideo(content[msg.GetIndex()])
else if (msg.isScreenClosed())
return -1
end if
endif
end while

End Function

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

metaData = {
ContentType: "episode",
Title: content.data.caption,
Description: content.data.caption,
Stream: {
Url: content.data.progressive_url
}
}
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
1 REPLY 1
RokuJoel
Binge Watcher

Re: Parsing Livestream events JSON

Well, this looks kinda wrong:

?callback=?

usually that would be something like

?callback=value

otherwise you would leave the ?callback= out of the url entirely if you aren't passing some kind of value to the server in the query portion of the URL.

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