Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
arifimam
Visitor

How to add a Play All button?

I need to add a Play All button on detailScreen, I am using videopalyer example. please help. I have a very little programming knowledge, but I already made a couple of channels using Roku sdk samples without any problem, here is an example
https://owner.roku.com/add/QBZNN

Thanks
0 Kudos
10 REPLIES 10
jbrave
Channel Surfer

Re: How to add a Play All button?

first, modify your detail screen function to accept the full list of videos instead of just a single video:


function detailscreen(videolist as object,index as integer)


then instead of calling the detail screen with just the single item, pass the whole list and the index number of the single item to display, use the index to display the correct item:

screen.setcontent(videolist[index])


add a button to the detail screen with the text "Play All"


screen.addbutton(3,"Play All Videos")


in your if then add a section:

if msg.getindex()=3 then
for each video in videolist
returnvalue=showvideoscreen(video)
if returnvalue=-1 then
exit for
end if
next

Modify the video player to return a -1 if the user exits the videoplayer (as opposed to the video ends on its own) and a -2 if the video ends on its own:

				else if msg.isfullresult()
?"video ended"
return -2
else if msg.isScreenClosed() then 'ScreenClosed event
print "screen closed event"
return -1


That is the gist of it.
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
arifimam
Visitor

Re: How to add a Play All button?

Jbrave, thanks for your help, but I am a bit confused about where to add these codes, below is my detail screen code, can you please please modify this?

'**********************************************************
'** Video Player Example Application - Detail Screen
'** November 2009
'** Copyright (c) 2009 Roku Inc. All Rights Reserved.
'**********************************************************

Function preShowDetailScreen(breadA=invalid, breadB=invalid) As Object
port=CreateObject("roMessagePort")
screen = CreateObject("roSpringboardScreen")
screen.SetDescriptionStyle("video")
screen.SetMessagePort(port)
if breadA<>invalid and breadB<>invalid then
screen.SetBreadcrumbText(breadA, breadB)
end if

return screen
End Function

'***************************************************************
'** The show detail screen (springboard) is where the user sees
'** the details for a show and is allowed to select a show to
'** begin playback. This is the main event loop for that screen
'** and where we spend our time waiting until the user presses a
'** button and then we decide how best to handle the event.
'***************************************************************
Function showDetailScreen(screen As Object, showList As Object, showIndex as Integer) As Integer

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

refreshShowDetail(screen, showList, showIndex)

'remote key id's for left/right navigation
remoteKeyLeft = 4
remoteKeyRight = 5

while true
msg = wait(0, screen.GetMessagePort())

if type(msg) = "roSpringboardScreenEvent" then
if msg.isScreenClosed()
print "Screen closed"
exit while
else if msg.isRemoteKeyPressed()
print "Remote key pressed"
if msg.GetIndex() = remoteKeyLeft then
showIndex = getPrevShow(showList, showIndex)
if showIndex <> -1
refreshShowDetail(screen, showList, showIndex)
end if
else if msg.GetIndex() = remoteKeyRight
showIndex = getNextShow(showList, showIndex)
if showIndex <> -1
refreshShowDetail(screen, showList, showIndex)
end if
endif
else if msg.isButtonPressed()
print "ButtonPressed"
print "ButtonPressed"
if msg.GetIndex() = 1
PlayStart = RegRead(showList[showIndex].ContentId)
if PlayStart <> invalid then
showList[showIndex].PlayStart = PlayStart.ToInt()
endif
showVideoScreen(showList[showIndex])
endif
if msg.GetIndex() = 2
showList[showIndex].PlayStart = 0
showVideoScreen(showList[showIndex])
endif
if msg.GetIndex() = 3
endif
print "Button pressed: "; msg.GetIndex(); " " msg.GetData()
end if
else
print "Unexpected message class: "; type(msg)
end if
end while

return showIndex

End Function

'**************************************************************
'** Refresh the contents of the show detail screen. This may be
'** required on initial entry to the screen or as the user moves
'** left/right on the springboard. When the user is on the
'** springboard, we generally let them press left/right arrow keys
'** to navigate to the previous/next show in a circular manner.
'** When leaving the screen, the should be positioned on the
'** corresponding item in the poster screen matching the current show
'**************************************************************
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()
screen.AddButton(2, "Play from beginning")
screen.AddButton(1, "Resume Playing")

screen.SetContent(show)
screen.Show()

End Function

'********************************************************
'** Get the next item in the list and handle the wrap
'** around case to implement a circular list for left/right
'** navigation on the springboard screen
'********************************************************
Function getNextShow(showList As Object, showIndex As Integer) As Integer
if validateParam(showList, "roArray", "getNextShow") = false return -1

nextIndex = showIndex + 1
if nextIndex >= showList.Count() or nextIndex < 0 then
nextIndex = 0
end if

show = showList[nextIndex]
if validateParam(show, "roAssociativeArray", "getNextShow") = false return -1

return nextIndex
End Function


'********************************************************
'** Get the previous item in the list and handle the wrap
'** around case to implement a circular list for left/right
'** navigation on the springboard screen
'********************************************************
Function getPrevShow(showList As Object, showIndex As Integer) As Integer
if validateParam(showList, "roArray", "getPrevShow") = false return -1

prevIndex = showIndex - 1
if prevIndex < 0 or prevIndex >= showList.Count() then
if showList.Count() > 0 then
prevIndex = showList.Count() - 1
else
return -1
end if
end if

show = showList[prevIndex]
if validateParam(show, "roAssociativeArray", "getPrevShow") = false return -1

return prevIndex
End Function
0 Kudos
jbrave
Channel Surfer

Re: How to add a Play All button?

Well, given the template you are using already has some of this built into it:

1. screen.addbutton(3,"Play All") goes in function refreshdetailscreen()
2. in ShowDetailScreen, the for each goes into if msg.getindex()=3 which already exists
3. the foreach:

for each video in videolist
showList[showIndex].PlayStart = 0
returnvalue=showVideoScreen(video)
if returnvalue=-1 then
exit for
end if
next


You didn't include your showvideoscreen, but essentially, you need to look for an isscreenclosed() event and return a -1 if the screen is closed, and something else like -2 if isfullresult()
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
karmacode
Visitor

Re: How to add a Play All button?

Hello,
I am also interested in enabling the 'Play All' functionality. However, the app gets frozen at the end of the loading screen for the second video in the playlist. It plays fine the first video I pick. Any reason you can think of why this is happening?
http://www.connectedtvforum.com
0 Kudos
jbrave
Channel Surfer

Re: How to add a Play All button?

There are really a lot of reasons why this might happen. Is it always the same video that freezes? What if you pick the second vid as your first vid, does it play? In your video player module, interrupt program execution and print out the contents of the data you are sending for the first video, then type cont to continue running your program, then when the second vid freezes up, interrupt again (ctrl-c) and print the next video. compare the output from both.

It could also be a server issue, or that second video isn't correctly encoded. Take some time to eliminate each possible cause. If I was a betting man, I would bet that either the data you are sending to the video player for the next video is somehow incorrect, or your video is improperly encoded.

- Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
DJ_Lucas
Visitor

Re: How to add a Play All button?

You didn't include your showvideoscreen, but essentially, you need to look for an isscreenclosed() event and return a -1 if the screen is closed, and something else like -2 if isfullresult()


Hello, new user and also want the same functionality. Very green, around 2 hours now, but I have my first edits of the videoplayer sample working already with content and ratings. Unfortunately, either I still don't completely understand the language (and I assure you, I do not! all trial and error so far), or the above does not apply directly to the videoplayer sample.

Here is the whole of showVideoScreen():

Function showVideoScreen(episode As Object)

if type(episode) <> "roAssociativeArray" then
print "invalid data passed to showVideoScreen"
return -1
endif

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

screen.Show()
screen.SetPositionNotificationPeriod(30)
screen.SetContent(episode)
screen.Show()

'Uncomment his line to dump the contents of the episode to be played
'PrintAA(episode)

while true
msg = wait(0, port)

if type(msg) = "roVideoScreenEvent" then
print "showHomeScreen | msg = "; msg.getMessage() " | index = "; msg.GetIndex()
if msg.isScreenClosed()
print "Screen closed"
exit while
elseif msg.isRequestFailed()
print "Video request failure: "; msg.GetIndex(); " " msg.GetData()
elseif msg.isStatusMessage()
print "Video status: "; msg.GetIndex(); " " msg.GetData()
elseif msg.isButtonPressed()
print "Button pressed: "; msg.GetIndex(); " " msg.GetData()
elseif msg.isPlaybackPosition() then
nowpos = msg.GetIndex()
RegWrite(episode.ContentId, nowpos.toStr())
else
print "Unexpected event type: "; msg.GetType()
end if
else
print "Unexpected message class: "; type(msg)
end if
end while

End Function


In the videoplayer example, -1 return value is already used. I'm still green so any corrections would be great, but I believe that I should test on returnvalue=-2 in if msg.getindex()=3 in the sample detail screen you show above..does the following look correct?


-----showVideoScreen()-----

if msg.isFullResult()
print "Video ended correctly"
return -3
elseif msg.isScreenClosed()
print "Screen closed"
return -2
elseif msg.isRequestFailed()
print "Video request failure: "; msg.GetIndex(); " " msg.GetData()


-----showDetailScreen()-----

if msg.GetIndex() = 3
for each video in showList
showList[showIndex].PlayStart = 0
returnvalue=showVideoScreen(video)
if returnvalue=-2 then
exit for
end if
next
endif


Thanks in advance.

-- DJ Lucas
0 Kudos
remembergod
Visitor

Re: How to add a Play All button?

After press on "play all button", once I would like to stop it and press "back button", it will skip the current video and play the next one.

How to let it return to the main menu after press "back button"?

Thanks.
0 Kudos
agmark
Visitor

Re: How to add a Play All button?

I'm not sure I understand what you want the channel to do. Can you explain it again? Maybe one of the experts here can help with suggestions.

Do you want to create a "Skip" routine if a specific button is pressed while a video is playing or do you want to exit the video and return directly to the main posterscreen? I suspect the proper function of hitting a back button would be to exit the while loop in the springboardscreen and return you back to the posterscreen. Maybe others have a better idea of what you're trying to do.

good luck.

"remembergod" wrote:
After press on "play all button", once I would like to stop it and press "back button", it will skip the current video and play the next one.

How to let it return to the main menu after press "back button"?

Thanks.
0 Kudos
remembergod
Visitor

Re: How to add a Play All button?

currently, press "play all" -> loop all video -> press "back" during loop -> it skips current video and play the next one.

How to change the follow as following:
press "play all" -> loop all video -> press "back" during loop -> it will stop current video and go to main screen.

Or any button can stop the loop?

Thanks
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.