Parsing Livestream events JSON

Roku's free SDK allows developers to build channels and applications and publish them to the Roku Channel Store. Register for the Developer Program at http://www.roku.com/developer

Moderators: RokuDouglas, RokuKen, RokuRyan, RokuJamesL, RokuChris, RokuJoel

Parsing Livestream events JSON

Postby trinay » Tue Aug 20, 2013 3:20 am

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.

Code: Select all
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

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

Re: Parsing Livestream events JSON

Postby RokuJoel » Tue Aug 20, 2013 3:44 pm

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
RokuJoel
 
Posts: 1096
Joined: Mon Nov 14, 2011 5:22 pm


Return to Roku Developer Program

Who is online

Users browsing this forum: No registered users and 3 guests