Your Digital Media Has Never Looked So Good

Moderators: RokuKen, RokuRyan, RokuJamesL, RokuWinston, RokuJoel, RokuChrisT, RokuChris, RokuDanny

Topic Author
Posts: 5
Joined: Mon Jul 29, 2013 2:08 am

Parsing Livestream events JSON

Tue Aug 20, 2013 3:20 am


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 )

    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
    while (true)
        msg = wait(0, port)
        if type( msg ) = "roParagraphScreenEvent"
            if (msg.isButtonPressed())
            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"

End Function

Function HandleButtonPress(id as integer) as void
End Function

Function LoadJSONFile() as void
    'jsonAsString = ReadAsciiFile("")
    xfer = CreateObject("roUrlTransfer")
    jsonAsString = xfer.GetToString()
    m.json = ParseJSON(jsonAsString)
End Function

Function ShowPosterScreen(feed as object) as integer
    posterScreen = CreateObject("roPosterScreen")
    port = CreateObject("roMessagePort")
    posterScreen.SetBreadcrumbText("LiveStream Playlist Result", "")
    contentList = CreateObject("roArray", 2, true)
    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 )

    while (true)
        msg = wait(0, port)
        if type(msg) = "roPosterScreenEvent"
            if (msg.isListItemSelected())
            else if (msg.isScreenClosed())
                return -1
            end if
    end while

End Function

Function PlayVideo(content as object) as integer
    videoScreen = CreateObject("roVideoScreen")
    port = CreateObject("roMessagePort")
    videoScreen.SetMessagePort( port )
        metaData = {
            ContentType: "episode",
            Stream: {
    videoScreen.SetContent( metaData )
    while (true)
        msg = wait(0, port)
        if type(msg) = "roVideoScreenEvent"
            if (msg.isScreenClosed())
                return -1
            end if
    end while       
End Function

User avatar
Posts: 1744
Joined: Mon Nov 14, 2011 5:22 pm

Re: Parsing Livestream events JSON

Tue Aug 20, 2013 3:44 pm

Well, this looks kinda wrong:


usually that would be something like


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

Who is online

Users browsing this forum: No registered users and 0 guests