content: ' ********************************************************************
  ' **  Sample PlayVideo App
  ' **  Copyright (c) 2009 Roku Inc. All Rights Reserved.
  ' ********************************************************************
  
  Sub Main(args As Dynamic)
      'initialize theme attributes like titles, logos and overhang color
      initTheme()
  
      'test to use some json
      http = NewHttp("http://people.fas.harvard.edu/~jmueller/roku_json/test.json")
      rsp = http.GetToStringWithRetry()
      json = BSJSON()
      myjson = json.JsonDecode(rsp)
  
      'has to live for the duration of the whole app to prevent flashing
      'back to the roku home screen.
      screenFacade = CreateObject("roPosterScreen")
      screenFacade.show()
  
      showSpringboardScreen(myjson.paul_farmer) 
      
      'exit the app gently so that the screen doesn't flash to black
      screenFacade.showMessage("")
      sleep(25)
  End Sub
  
  '*************************************************************
  '** Set the configurable theme attributes for the application
  '** 
  '** Configure the custom overhang and Logo attributes
  '*************************************************************
  
  Sub initTheme()
  
      app = CreateObject("roAppManager")
      theme = CreateObject("roAssociativeArray")
  
      theme.OverhangPrimaryLogoOffsetSD_X = "72"
      theme.OverhangPrimaryLogoOffsetSD_Y = "15"
      theme.OverhangSliceSD = "pkg:/images/Overhang_BackgroundSlice_SD43.png"
      theme.OverhangPrimaryLogoSD  = "pkg:/images/Logo_Overhang_SD43.png"
  
      theme.OverhangPrimaryLogoOffsetHD_X = "123"
      theme.OverhangPrimaryLogoOffsetHD_Y = "20"
      theme.OverhangSliceHD = "pkg:/images/Overhang_BackgroundSlice_HD.png"
      theme.OverhangPrimaryLogoHD  = "pkg:/images/Logo_Overhang_HD.png"
      
      app.SetTheme(theme)
  
  End Sub
  
  
  '*************************************************************
  '** showSpringboardScreen()
  '*************************************************************
  
  Function showSpringboardScreen(item as object) As Boolean
      port = CreateObject("roMessagePort")
      screen = CreateObject("roSpringboardScreen")
  
      print "showSpringboardScreen"
      
      screen.SetMessagePort(port)
      screen.AllowUpdates(false)
      if item <> invalid and type(item) = "roAssociativeArray"
          screen.SetContent(item)
      endif
  
      screen.SetDescriptionStyle("generic") 'audio, movie, video, generic
                                          ' generic+episode=4x3,
      screen.ClearButtons()
      screen.AddButton(1,"Play")
      screen.AddButton(2,"Go Back")
      screen.SetStaticRatingEnabled(false)
      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(item)
                      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(args As Dynamic)
      print "Displaying video: "
      p = CreateObject("roMessagePort")
      video = CreateObject("roVideoScreen")
      video.setMessagePort(p)
  
      video.SetContent(args)
      video.show()
  
      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.isRequestFailed()
                  print "play failed: "; msg.GetMessage()
              else
                  print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
              endif
          end if
      end while
  End Function
  
  