Forum Discussion

recordlikedanie's avatar
13 years ago

how to create screen stacks in simplevideoplayer template

What is the best way to create a second screen in appMain.brs from simplevideoplayer? I have the first button mapped to a 'HLS' live stream, the second button I want to send to a second screen showing categories for VOD playback. In each Category click I need to have the videos in the category... How's the best way to do this?

8 Replies

  • You could probably do this just by creating a new posterscreen, call screen=preshowposterscreen() then showposterscreen(screen,category), but you'll probably need to make some modifications in order to get categories and shows that are not in the initial set that you've downloaded.

    - Joel
  • Thanks for the quick reply.

    Would I need to have a separate appPosterScreen.brs file for this? What code do I need to use call it? I started working with the videoplayer example and now I've switched to the simplevideoplayer example because it has the kind of home screen we want. But I don't know very much about BrightScript yet or any coding for that matter [but I want to learn], so I'm still at the basic level. Here's the code I have for appMain.brs.

    ' ********************************************************************
    ' ** 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()

    if type(args) = "roAssociativeArray" and type(args.url) = "roString" then
    displayVideo(args)
    end if
    print "Type args = "; type(args)
    print "Type args.url = "; type(args.url)

    'has to live for the duration of the whole app to prevent flashing
    'back to the roku home screen.
    screenFacade = CreateObject("roPosterScreen")
    screenFacade.show()

    itemMpeg4 = { ContentType:"episode"
    SDPosterUrl:"file://pkg:/images/DanGilbert.jpg"
    HDPosterUrl:"file://pkg:/images/DanGilbert.jpg"
    IsHD:False
    HDBranded:False
    ShortDescriptionLine1:"Dan Gilbert asks, Why are we happy?"
    ShortDescriptionLine2:""
    Description:"Harvard psychologist Dan Gilbert says our beliefs about what will make us happy are often wrong -- a premise he supports with intriguing research, and explains in his accessible and unexpectedly funny book, Stumbling on Happiness."
    Rating:"NR"
    StarRating:"80"
    Length:1280
    Categories:["Technology","Talk"]
    Title:"Dan Gilbert asks, Why are we happy?"
    }

    itemVenter = { ContentType:"episode"
    SDPosterUrl:"file://pkg:/images/CraigVenter-2008.jpg"
    HDPosterUrl:"file://pkg:/images/CraigVenter-2008.jpg"
    IsHD:False
    HDBranded:False
    ShortDescriptionLine1:"Can we create new life out of our digital universe?"
    ShortDescriptionLine2:""
    Description:"He walks the TED2008 audience through his latest research into fourth-generation fuels -- biologically created fuels with CO2 as their feedstock. His talk covers the details of creating brand-new chromosomes using digital technology, the reasons why we would want to do this, and the bioethics of synthetic life. A fascinating Q&A with TED's Chris Anderson follows."
    Rating:"NR"
    StarRating:"80"
    Length:1972
    Categories:["Technology","Talk"]
    Title:"Craig Venter asks, Can we create new life out of our digital universe?"
    }

    itemMissionTV = { ContentType:"episode"
    SDPosterUrl:"file://pkg:/images/MainMenu.png"
    HDPosterUrl:"file://pkg:/images/MainMenu.png"
    IsHD:true
    HDBranded:true
    ShortDescriptionLine1:"Watch mission videos anytime!"
    ShortDescriptionLine2:""
    Description:"Mission TV is a 24/7 channel devoted to the Great Commission of Matthew 28:17-20. Watch front line mission video adventures and see interviews of missionaries who have been there. Most of all, get encouraged to be a part of hastening the coming of Christ by giving the Gospel to the world."
    Rating:"NR"
    StarRating:"80"
    Length:600
    Categories:["Gospel","Christian"]
    Title:"Watch mission videos anytime!"
    }

    'showSpringboardScreen(itemVenter)
    'showSpringboardScreen(itemMpeg4) 'uncomment this line and comment out the next to see the old mpeg4 example
    showSpringboardScreen(itemMissionTV) 'uncomment this line to see the BigBuckBunny example

    '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.OverhangOffsetSD_X = "72"
    theme.OverhangOffsetSD_Y = "31"
    theme.OverhangSliceSD = "pkg:/images/Overhang_Background_SD.png"
    theme.OverhangLogoSD = "pkg:/images/Overhang_Logo_SD.png"

    theme.OverhangOffsetHD_X = "125"
    theme.OverhangOffsetHD_Y = "35"
    theme.OverhangSliceHD = "pkg:/images/Overhang_Background_HD.png"
    theme.OverhangLogoHD = "pkg:/images/Overhang_Logo_HD.png"

    theme.BackgroundColor = "#000000"

    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 Live Stream")
    screen.AddButton(2,"Play On Demand Videos")
    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("")
    else if msg.GetIndex() = 2
    InitContentList("1")
    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)

    'bitrates = [0] ' 0 = no dots, adaptive bitrate
    'bitrates = [348] ' <200 Kbps = 1 dot
    'bitrates = [664] ' <600 Kbps = 2 dots
    'bitrates = [996] ' <1.1Mbps = 3 dots
    'bitrates = [2048] ' >=1.6Mbps = 4 dots
    'bitrates = [0]

    'Low Bandwidth'
    urls = ["http://[realhost-low]/playlist.m3u8"]
    bitrates = [348]
    qualities = ["SD"]
    StreamFormat = "HLS"
    title = "Loading Stream... Auto-Bandwidth Low"
    srt = ""

    'Medium Bandwidth'
    urls = ["http://[realhost-medium]/playlist.m3u8"]
    bitrates = [664]
    qualities = ["SD"]
    StreamFormat = "HLS"
    title = "Loading Stream... Auto-Bandwidth Medium"
    srt = ""

    'High Bandwidth'
    urls = ["http://[realhost-high]/playlist.m3u8"]
    bitrates = [2048]
    qualities = ["SD"]
    StreamFormat = "HLS"
    title = "Loading Stream... Auto-Bandwidth High"
    srt = ""

    'Ted Talks'
    'urls = ["[code][/code]"]
    'qualities = ["SD"]
    'StreamFormat = "mp4"
    'title = "Loading Stream..."

    ' Apple's HLS test stream
    'urls = ["http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"]
    'qualities = ["SD"]
    'streamformat = "hls"
    'title = "Apple BipBop Test Stream"


    if type(args) = "roAssociativeArray"
    if type(args.url) = "roString" and args.url <> "" then
    urls[0] = args.url
    end if
    if type(args.StreamFormat) = "roString" and args.StreamFormat <> "" then
    StreamFormat = args.StreamFormat
    end if
    if type(args.title) = "roString" and args.title <> "" then
    title = args.title
    else
    title = ""
    end if
    if type(args.srt) = "roString" and args.srt <> "" then
    srt = args.StreamFormat
    else
    srt = ""
    end if
    end if

    videoclip = CreateObject("roAssociativeArray")
    videoclip.StreamBitrates = bitrates
    videoclip.StreamUrls = urls
    videoclip.switchingStrategy = "full-adaptation"
    videoclip.StreamQualities = qualities
    videoclip.StreamFormat = StreamFormat
    videoclip.Title = title
    videoclip.Live = True

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

    video.SetContent(videoclip)
    video.show()

    lastSavedPos = 0
    statusInterval = 10 'position must change by more than this number of seconds before saving

    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, So I've tried to do this as much as I can, I've basically copied the code from the video player example I had setup before and set it as a new file (appPosterScreen.brs), but now It's crashing and I'm getting this in the debugger... Any ideas?


    Current Function:
    012: Function preShowPosterScreen(breadA=invalid, breadB=invalid) As Object
    013:
    014: if validateParam(breadA, "roString", "preShowPosterScreen", true) = false return -1
    015: if validateParam(breadB, "roString", "preShowPosterScreen", true) = false return -1
    016:
    017: port=CreateObject("roMessagePort")
    018: screen = CreateObject("roPosterScreen")
    019: screen.SetMessagePort(port)
    020: if breadA<>invalid and breadB<>invalid then
    021: screen.SetBreadcrumbText(breadA, breadB)
    022: end if
    023:
    024: screen.SetListStyle("arced-landscape")
    025: return screen
    026:
    027: End Function
    Function Call Operator ( ) attempted on non-function. (runtime error &he0) in ...g:/source/appPosterScreen.brs(14)

    014: if validateParam(breadA, "roString", "preShowPosterScreen", true) = false return -1
    Backtrace:
    Function preshowposterscreen(breada As ) As
    file/line: /tmp/plugin/LABAAAswQzn8...g:/source/appPosterScreen.brs(14)
    Function showspringboardscreen(item As <uninitialized>) As Boolean
    file/line: /tmp/plugin/LABAAAswQzn8/pkg:/source/appMain.brs(141)
    Function main(args As ) As
    file/line: /tmp/plugin/LABAAAswQzn8/pkg:/source/appMain.brs(68)

    Local Variables:
    breada &h0100 String (VT_STR_CONST) val:
    breadb &h0080 Invalid val:invalid
    global &h0020 rotINTERFACE:ifGlobal
    m &h0010 bsc:roAssociativeArray, refcnt=4
    port &h0000 <uninitialized> val:Uninitialized
    screen &h0000 <uninitialized> val:Uninitialized
    validateparam &h0000 <uninitialized> val:Uninitialized
  • Function Call Operator ( ) attempted on non-function. (runtime error &he0) in ...g:/source/appPosterScreen.brs(14)

    014: if validateParam(breadA, "roString", "preShowPosterScreen", true) = false return -1


    validateparam &h0000 <uninitialized> val:Uninitialized


    It's telling you that it can't find a definition for the function validateParam anywhere in your channel. You need to find the function definition in the channel you borrowed that code from and include it in your channel.
  • Thanks for the reply! So I need to find the part where it says 'Function validateParam...' ? I'm curious, what does this function actually do?
  • I found the function validateParam and added it into the channel... but now I have another problem. Sorry I don't know how to interpret these yet. The channel is still crashing and the debugger is showing this:

    invalid parameter of type roInvalid for roString in function preShowPosterScreen
  • Here is my preShowPosterScreen code:

    Function preShowPosterScreen(breadA=invalid, breadB=invalid) As Object

    if validateParam(breadA, "roString", "preShowPosterScreen", true) = false return -1
    if validateParam(breadB, "roString", "preShowPosterScreen", true) = false return -1

    port=CreateObject("roMessagePort")
    screen = CreateObject("roPosterScreen")
    screen.SetMessagePort(port)
    if breadA<>invalid and breadB<>invalid then
    screen.SetBreadcrumbText(breadA, breadB)
    end if

    screen.SetListStyle("arced-landscape")
    return screen

    End Function
  • Does anyone know what this error from debugger means?

    invalid parameter of type roInvalid for roString in function preShowPosterScreen