Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
davidlgood
Level 8

Set "Play/Resume" Based on XML

Sorry if this is an obvious question, but I'm a bit stumped. I have a channel that shows "live" (hls) streams and also "archive" (mp4) streams -- through two different screens and populated with two different XML documents.

In my appDetailScreen.brs file I have the following function for button assignments based on if a user has viewed a video for more than 30 seconds, or not:

Function refreshShowDetail(screen As Object, showList As Object, showIndex as Integer) As Integer

if validateParam(screen, "roSpringboardScreen", "refreshShowDetail") = false return -1
if validateParam(showList, "roArray", "refreshShowDetail") = false return -1

show = showList[showIndex]

'Uncomment this statement to dump the details for each show
'PrintAA(show)

screen.ClearButtons()
if regread(show.contentid) <> invalid and regread(show.contentid).toint() >=30 then
screen.AddButton(1, "Resume playing")
screen.AddButton(2, "Play from beginning")
else
screen.addButton(2,"Play")
end if
screen.SetStaticRatingEnabled(false)
screen.SetContent(show)
screen.Show()

End Function


So far, nothing new. This works just fine for video-on-demand (mp4) files. What I would like to do is alter the code so that if a user is playing back a "live" stream (hls) the only option available is "Play" or "Play Live Stream" -- something like that. Is there a way to add an additional if statement to the code above that would look at the XML file and, based on something like <contentType> or <streamFormat> give the user only a "Play Live Stream" option?

I was playing around with:

if showList[showIndex].contentType = "LiveStream" then
screen.AddButton(2, "Play Live Stream")


and I even tried

if show.contentType = "LiveStream then
screen.AddButton(2, "Play Live Stream")


But I'm either missing something here, or not understanding or overlooking a very basic concept for the programming language. For reference, here is one of my many failed attempts:

Function refreshShowDetail(screen As Object, showList As Object, showIndex as Integer) As Integer

if validateParam(screen, "roSpringboardScreen", "refreshShowDetail") = false return -1
if validateParam(showList, "roArray", "refreshShowDetail") = false return -1

show = showList[showIndex]

'Uncomment this statement to dump the details for each show
'PrintAA(show)

screen.ClearButtons()
if showList[showIndex].contentType = "LiveStream" then
screen.AddButton(2, "Play Live Stream")
else if regread(show.contentid) <> invalid and regread(show.contentid).toint() >=30 then
screen.AddButton(1, "Resume playing")
screen.AddButton(2, "Play from beginning")
else
screen.addButton(2,"Play")
end if
screen.SetStaticRatingEnabled(false)
screen.SetContent(show)
screen.Show()

End Function


In my XML document each video (live, or VOD) has either <contentType>LiveStream</contentType> or <contentType>Archive</contentType>

Any help someone can provide would be very much appreciated.
0 Kudos
5 REPLIES 5\
destruk
Level 10

Re: Set "Play/Resume" Based on XML

This doesn't answer your main question, but if your springboard is only going to have a single option for a livestream, why not just play the live stream automatically?
0 Kudos
davidlgood
Level 8

Re: Set "Play/Resume" Based on XML

"destruk" wrote:
This doesn't answer your main question, but if your springboard is only going to have a single option for a livestream, why not just play the live stream automatically?


The livestreams for this channel are usually only about two hours long, per week (on various days) -- the rest of the time they are dead. So I use the springboard to also display "live" times and other information. If the streams were on 24/7, your suggestion would be the best solution.
0 Kudos
destruk
Level 10

Re: Set "Play/Resume" Based on XML

In that case you should only be offering the live stream icon as a selectable option when it is up and active.
ie using a gridscreen or the poster screen, if the livestream is available, have the xml include it as an option, and if it is down, don't display the selection

OR

Use the description bubble for the selection, and/or the short description line 1/line 2 to display the times it is available and when the user selects it, immediately connect and play it
A gridscreen allows you to have a complete description bubble for the content with availability information, some poster screen types allow for the description to be displayed as well as short description lines, etc

It just makes for a cleaner interface than to have it display a springboard with a single choice that may or may not do anything IMO.
As to why it's not working with your code, posting the xml parsing/showfeed routine as well as any debug information available would help troubleshoot.
0 Kudos
destruk
Level 10

Re: Set "Play/Resume" Based on XML

I had posted a couple pages of debugging tips but it was lengthy and a bit confusing, so ... - to me it looks like your code is ok, but I wouldn't recommend using "contenttype" as your flag to determine if it is live or not - as that is a reserved/utilized meta data variable for how the springboard screens are displayed to the user - see the SDK component reference - valid values are movie, season, series, audio, episode... It's better to add a new field so you can still modify springboard screens to what you need them to be.

Also having items share button id's isn't usually a very good practice either.

ie in your code you have Live Streaming Button as ID #2, as well as Play from Beginning as Button ID #2 - this means in your wait routine you'll need to check if it is live streaming or not when the button is selected, or in your play routine that is used for both discrete button type #2s if it is mp4 or hls /ism (microsoft smooth streaming)

Button IDs can be any integer - buttons are added in the order you add them in the script - so if you specify addbutton(99,"Play") and then addbutton(3,"Play from Beginning"), 99 will show up first as it was added first.
0 Kudos
davidlgood
Level 8

Re: Set "Play/Resume" Based on XML

THANK YOU!! This reply has actually helped me in more ways than you can imagine -- triggered some very obvious things I totally zoned out on. And yes, I agree -- using contenttype is not the best thing to do (I was just grasping at names for example purposes, which I shouldn't have done since it can get confusing when you accidentally use a name that serves an actual purpose).

The button ID bit is what I needed to hear -- TOTALLY got backwards on that, so I'm glad you said something.

Really great help -- thanks!!
0 Kudos