search by combining simple video/poster examples with xml

The XML style that works with video Player example:

<feed>
   <item sdImg="http://xxxx.com/imagees/videos/1993.jpg" hdImg="http://xxxx.com/images/videos/1993.jpg">
      <title>Hernandez</title>
      <contentId>10001</contentId>
      <contentType>Fight</contentType>
      <contentQuality>SD</contentQuality>
      <media>
         <streamFormat>mp4</streamFormat>
         <streamQuality>SD</streamQuality>
         <streamBitrate>700</streamBitrate>
         <streamUrl>http://xxxx.com/roku/video/1993.mp4</streamUrl>
      </media>
      <synopsis>Leo Hernandez</synopsis>
      <genres>Clip</genres>
      <runtime>703</runtime>
   </item>   
   

   <item sdImg="http://xxxx.com/imagees/videos/1994.jpg" hdImg="http://xxxx.com/images/videos/1994.jpg">
      <title>Leo</title>
      <contentId>10002</contentId>
      <contentType>Fight</contentType>
      <contentQuality>SD</contentQuality>
      <media>
         <streamFormat>mp4</streamFormat>
         <streamQuality>SD</streamQuality>
         <streamBitrate>700</streamBitrate>
         <streamUrl>http://xxxx.com/roku/video/1994.mp4</streamUrl>
      </media>
           <synopsis>Leo</synopsis>
          <genres>Clip</genres>
          <runtime>703</runtime>
   </item>   
</feed>

and here is the code so far:

' *********************************************************
' **  Simple Poster Screen Demonstration App
' **  Nov 2009
' **  Copyright (c) 2009 Roku Inc. All Rights Reserved.
' *********************************************************

'************************************************************
'** Application startup
'************************************************************
Sub Main()

    'initialize theme attributes like titles, logos and overhang color
    initTheme()

    'prepare the screen for display and get ready to begin
    screen=preShowPosterSearchScreen("", "Search Results")
    if screen=invalid then
        print "unexpected error in preShowPosterScreen"
        return
    end if

    'set to go, time to get started
    showPosterSearchScreen(screen)

End Sub

'*************************************************************

Sub initTheme()

    app = CreateObject("roAppManager")
    theme = CreateObject("roAssociativeArray")

    theme.OverhangOffsetSD_X = "72"
    theme.OverhangOffsetSD_Y = "25"
    theme.OverhangSliceSD = "pkg:/images/Overhang_BackgroundSlice_Blue_SD43.png"
    theme.OverhangLogoSD  = "pkg:/images/Logo_Overhang_Roku_SDK_SD43.png"

    theme.OverhangOffsetHD_X = "123"
    theme.OverhangOffsetHD_Y = "48"
    theme.OverhangSliceHD = "pkg:/images/Overhang_BackgroundSlice_Blue_HD.png"
    theme.OverhangLogoHD  = "pkg:/images/Logo_Overhang_Roku_SDK_HD.png"

    app.SetTheme(theme)

End Sub
  
'******************************************************
Function preShowPosterSearchScreen(breadA=invalid, breadB=invalid) As Object

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

    if breadA<>invalid and breadB<>invalid then
        screen.SetBreadcrumbText(breadA, breadB)
    end if

    screen.SetListStyle("flat-category")
    return screen

End Function

'******************************************************
Function showPosterSearchScreen(screen As Object) As Integer

    categoryList = getSearchList()
    screen.SetListNames(categoryList)
    screen.SetContentList(getShowsForSearchItem(categoryList[0]))

    item = getShowsForSearchItem(categoryList[0])
    screen.SetContentList(item)

   screen.Show()

    while true
        msg = wait(0, screen.GetMessagePort())
        if type(msg) = "roPosterScreenEvent" then
            if msg.isListFocused() then

m.curCategory = msg.GetIndex()

   screen.SetFocusedListItem(m.curShow)
   screen.SetContentList(getShowsForSearchItem(m.item, m.curCategory))

else if msg.isListItemFocused() then
      print "list item focused | current show = "; msg.GetIndex()
                
else if msg.isListItemSelected() then
  

showSpringboardScreen(item)

     else if msg.isScreenClosed() then
                return -1
            end if
        end If
    end while

End Function

'***************************************************************
Function getSearchList() As Object

    categoryList = CreateObject("roArray", 10, true)
    categoryList = [ "Search Results"  ]
    return categoryList

End Function

'********************************************************************

Function getShowsForSearchItem(item As Object) As Object
    
    'aa = CreateObject("roAssociativeArray")
    'aa.posteritems = CreateObject("roArray", 10, true)

    ' m.RegToken =  RegRead("RegToken", "XXX")
    ' token = m.RegToken

    m.UrlBase         = "http://xxxx.com/roku"
    m.UrlSearch       = m.UrlBase + "/xml/search.php"

    http = NewHttp(m.UrlSearch)
    ' http.AddParam("token", token)
    ' http.AddParam("genre", "")

    rsp = http.Http.GetToString()
    xml = CreateObject("roXMLElement")
  
    if not xml.Parse(rsp) then
        print "Can't parse response"
        ShowConnectionFailed()
        return ""
    end if

    if xml.GetName() <> "feed"
        Dbg("Bad register response: ",  xml.GetName())
        ShowConnectionFailed()
        return ""
    end if

    if islist(xml.GetBody()) = false then
        Dbg("No registration information available")
        ShowConnectionFailed()
        return ""
    end if

' item = []

For Each item in xml.item
     'initialize variables with empty strings, just in case they're missing in the XML

      ContentType =""
      SDPosterUrl =""
      HDPosterUrl =""
      ShortDescriptionLine1 =""
      ShortDescriptionLine2 =""
      Description =""
      Rating =""
      StarRating =""
      Categories =""
      Title =""
      urls =""
      qualities ="""
      StreamFormat =""
      srt =""

      ContentType =item.contentType.GetText()
      ShortDescriptionLine1 =item.title.GetText()
      ShortDescriptionLine2 =""
      Description =item.synopsis.GetText()
      Rating = item.rating.GetText()
      Genres = item.genres.GetText()
      StarRating =item.starrating.GetText()
      Categories =""
      Title =item.title.GetText()
      Runtime=item.runtime.GetText()   ' something about stroi here?

 '  these are actually part of <item sdImg= ""   hdImg=""/> 

      SDPosterUrl = item.image.GetText()       
      HDPosterUrl = item.image.GetText()       

 '  these are part of  <item> <media>

      urls = item.streamUrl.GetText()
      qualities = streamQuality.GetText()
      bitrates = streamBitrate.GetText()
      StreamFormat =item.streamFormat.GetText()
      srt =""

  
    'item =  CreatePosterItem(ContentType, SDPosterUrl,HDPosterUrl,ShortDescriptionLine1, ShortDescriptionLine2, Description, Rating, StarRating, Categories, Title)

 item = [
        {
               ContentType:"episode"
               SDPosterUrl:"http://i.ytimg.com/vi/nKZ-GjSaqgo/0.jpg"            ' for demo only not intended for hotlinking
               HDPosterUrl:"http://i.ytimg.com/vi/nKZ-GjSaqgo/0.jpg"
               IsHD:False
               HDBranded:False
               ShortDescriptionLine1:"Can we create new life out of universe?"
               ShortDescriptionLine2:""
               Description:"He walks the TED2008 audience through his."
               Rating:"NR"
               StarRating:"80"
               Length:1972
               Title:"Craig Venter asks, Can we createdigital universe?"
               urls:"http://video.ted.com/talks/podcast/CraigVenter_2008_480.mp4"
               qualities:"SD"
               StreamFormat:"mp4"
               srt:"file://pkg:/source/craigventer.srt"

        }
{
               ContentType:"episode"
               SDPosterUrl:"http://i.ytimg.com/vi/nKZ-GjSaqgo/0.jpg"    ' for demo only not intended for hotlinking
               HDPosterUrl:"http://i.ytimg.com/vi/nKZ-GjSaqgo/0.jpg"
               IsHD:False
               HDBranded:False
               ShortDescriptionLine1:"out of universe?"
               ShortDescriptionLine2:""
               Description:"audience through his."
               Rating:"NR"
               StarRating:"80"
               Length:1972
               Title:"Craig universe?"
               urls:"http://video.ted.com/talks/podcast/CraigVenter_2008_480.mp4"
               qualities:"SD"
               StreamFormat:"mp4"
               srt:"file://pkg:/source/craigventer.srt"

        }

                    ]

 ' aa.posteritems .push(item)

Next
   
    return item
'return aa

End Function

'*************************************************************
'** showSpringboardScreen()
'*************************************************************

Function showSpringboardScreen(item as object) As Boolean
    port = CreateObject("roMessagePort")
    screen = CreateObject("roSpringboardScreen")

    print "showSpringboardScreen"
    
    screen.SetMessagePort(port)
    screen.AllowUpdates(true)

    if item <> invalid and type(item) = "roAssociativeArray"
        screen.SetContent(item)
    endif

    screen.SetDescriptionStyle("video") 

'////////////////      Add buttons here     ////////////////     
                                  
    screen.ClearButtons()
    screen.AddButton(1,"Play")
    screen.AddButton(2,"Go Back")
    screen.SetStaticRatingEnabled(true)
    screen.AllowUpdates(true)
    screen.Show()

    downKey=3
    selectKey=6

'///////////////////////////////////////////////////////////

    while true
        msg = wait(0, screen.GetMessagePort())
        if type(msg) = "roSpringboardScreenEvent"
            if msg.isScreenClosed()
                print "Screen closed"
                exit while                
            else if msg.isButtonPressed()
                    print "Button pressed: "; msg.GetIndex(); " " msg.GetData()
                    if msg.GetIndex() = 1
                         displayVideo()
                    else if msg.GetIndex() = 2
                         return true
                    endif
            else
                print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
            endif
        else 
            print "wrong type.... type=";msg.GetType(); " msg: "; msg.GetMessage()
        endif
    end while

    return true
End Function

'*************************************************************
'** displayVideo()
'*************************************************************

Function displayVideo()
 
    p = CreateObject("roMessagePort")
    video = CreateObject("roVideoScreen")
    video.setMessagePort(p)

'/////////////////////////////////////////////////////
    bitrates  = [996]   
    urls:"http://video.ted.com/talks/podcast/CraigVenter_2008_480.mp4"
    qualities:"SD"
    StreamFormat:"mp4"
    srt:"file://pkg:/source/craigventer.srt"

'/////////////////////////////////////////////////////

    videoclip = CreateObject("roAssociativeArray")
    videoclip.StreamBitrates = bitrates
    videoclip.StreamUrls = item.urls
    videoclip.StreamQualities = item.qualities
    videoclip.StreamFormat =  item.StreamFormat
    videoclip.Title = item.Title

    print "srt = ";srt

    if srt <> invalid and srt <> "" then
        videoclip.SubtitleUrl = srt
    end if
    

    video.SetContent(videoclip)
    video.show()

    lastSavedPos   = 0
    statusInterval = 10 

'///////////////////////////////////////////////////////////////////

    while true
        msg = wait(0, video.GetMessagePort())
        if type(msg) = "roVideoScreenEvent"
            if msg.isScreenClosed() then 'ScreenClosed event
                print "Closing video screen"
                exit while
            else if msg.isPlaybackPosition() then
                nowpos = msg.GetIndex()
                if nowpos > 10000
                    
                end if
                if nowpos > 0
                    if abs(nowpos - lastSavedPos) > statusInterval
                        lastSavedPos = nowpos
                    end if
                end if
            else if msg.isRequestFailed()
                print "play failed: "; msg.GetMessage()
            else
                print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
            endif
        end if
    end while
End Function

Ok this code partially works but the following:

1.) the springboard is not displaying any of the items even though they are hardcoded ( something to do with how i called this:showSpringboardScreen(item))
2.) the only reason video will play is because is hard coded

what needs to be done is:
1.) parse the xml to get back results… especially and the images from inside the
2.) get the results from the xml to feed the actual videos as well.

This could serve as a great example for anyone trying to do combine these items, as the examples now only say it can be done it doesn’t show any way of getting it done. and this leaves us only with the video player example which is a monster in itself.

This is actually an attempt to use this to pull back a list of searched items from my server.

anyone checked this out and was able to make sense of it?

This will be good for anyone new coming by as well and help with less questions! :wink:

I guess i just ask too many questions, I will try and play with this tomorrow but its just not working out right.

might have to go ahead and change the XML for the search page, as long as it brings back those variables were good!

is there a better way to bring back the array to feed the posterscreen?

“dynamitemedia” wrote:
I guess i just ask too many questions
No you just ask questions that require too much legwork :face_with_tongue:

Damn you Endless!! i thought i had an answer!! :laughing: its funny i seen that same response the other day saying " will be back soon", cant remember where. least it didnt happen to me again.

i would think this one would be simple its all one file!! I been working on this for about 10 days so how you think i feel :oops:

thanks i just think im missing something simple, and I have read through the SDK but not much to go on with this one…

This when finished should go in as an official example as its useful to everyone! and hey if your gonna ask a question make it a good one! :wink:

Ok i almost got this working but it seems the issue is how do i get the results from the for loop to populate

i have tried a few combos and i am getting closer but the problem is the correct syntax of the results into


item = []

For Each song in xml.song
     'initialize variables with empty strings, just in case they're missing in the XML

the way it works hard coded is

item = [{   .....   } {   .....   }]

what would or should this look like after the for loop?

i see it reading the xml so i know its working up to that point…