Your Digital Media Has Never Looked So Good

 
arifimam
Topic Author
Posts: 8
Joined: Sat Feb 05, 2011 11:07 pm

How to add a Play All button?

Mon Aug 15, 2011 7:39 pm

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
 
jbrave
Posts: 716
Joined: Mon Mar 22, 2010 3:00 pm
Location: Ben Lomond, CA
Contact:

Re: How to add a Play All button?

Mon Aug 15, 2011 10:21 pm

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!
 
arifimam
Topic Author
Posts: 8
Joined: Sat Feb 05, 2011 11:07 pm

Re: How to add a Play All button?

Mon Aug 15, 2011 11:57 pm

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
 
jbrave
Posts: 716
Joined: Mon Mar 22, 2010 3:00 pm
Location: Ben Lomond, CA
Contact:

Re: How to add a Play All button?

Tue Aug 16, 2011 12:21 pm

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!
 
karmacode
Posts: 12
Joined: Wed Jul 20, 2011 8:38 am

Re: How to add a Play All button?

Tue Oct 18, 2011 8:11 pm

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
 
jbrave
Posts: 716
Joined: Mon Mar 22, 2010 3:00 pm
Location: Ben Lomond, CA
Contact:

Re: How to add a Play All button?

Thu Oct 20, 2011 4:15 am

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!
 
DJ_Lucas
Posts: 3
Joined: Sun Nov 06, 2011 3:53 am

Re: How to add a Play All button?

Sun Nov 06, 2011 4:26 am

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
 
remembergod
Posts: 10
Joined: Thu Jan 05, 2012 2:28 pm

Re: How to add a Play All button?

Mon Jan 09, 2012 8:07 pm

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.
 
agmark
Posts: 142
Joined: Thu Nov 10, 2011 8:29 am

Re: How to add a Play All button?

Tue Jan 10, 2012 6:26 pm

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.
 
remembergod
Posts: 10
Joined: Thu Jan 05, 2012 2:28 pm

Re: How to add a Play All button?

Mon Jan 16, 2012 8:33 pm

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
 
User avatar
TheEndless
** Valued Community Member **
Posts: 9231
Joined: Mon Oct 04, 2004 10:15 am
Location: US
Contact:

Re: How to add a Play All button?

Tue Jan 17, 2012 12:10 am

remembergod wrote:
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

You'll need to capture the isPartialResult() event to prevent continued playback after exiting the current video.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)

Who is online

Users browsing this forum: No registered users and 4 guests