Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
Baradanikto
Level 9

SampleVideoPlayer - Resume Playing problem

I seemed to have run into the same problem reported in this earlier post - "Help with videoplayer resume playing functionality".  I, too, designed my channel around the same sample and have run into the same issue(s).  I tried the code changes mentioned in the post, but, they don't seem to work for me.  Here's the current state of my loop, and, the attempts I've made to debug:

   
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
            else if msg.isRequestFailed()
                 print "Video request failure: "; msg.GetIndex(); " " msg.GetData() 
                 'RegWrite(episode.contentId, "0")
                 RegDelete(episode.contentId)
            else if msg.isFullResult()
                 print "Playback completed"
                 'RegWrite(episode.contentId, "0")
                 RegDelete(episode.contentId)
            else if msg.isStatusMessage()
                 print "Video status: "; msg.GetIndex(); " " msg.GetData() 
            else if msg.isButtonPressed()
                print "Button pressed: "; msg.GetIndex(); " " msg.GetData()
            else if msg.isPlaybackPosition() then
                nowpos = msg.GetIndex()
                RegWrite(episode.ContentId, nowpos.toStr())
            else
                print "Unexpected event type: "; msg.GetType()
                nowpos = msg.GetIndex()
                print "Current position: "; nowpos.ToStr()
                RegDelete(episode.contentId)
            end if
        else
            print "Unexpected message class: "; type(msg)
        end if
    end while


One thing I've noticed that may be related: when finished playing a video, I consistently get an "Unexpected event - 8" in my debug console.


showHomeScreen | msg = start of play | index =  0
Video status:  0  0
showHomeScreen | msg = playback position | index =  0
showHomeScreen | msg = playback position | index =  30
showHomeScreen | msg = playback position | index =  60
showHomeScreen | msg =  | index =  0
Unexpected event type:  8
Current position: 0
showHomeScreen | msg = end of stream | index =  0
Video status:  0  0
showHomeScreen | msg = Playback completed. | index =  0
Playback completed
showHomeScreen | msg = end of playlist | index =  0
Video status:  0  0

I tried researching the event types from roVideoScreenEvent and roVideoPlayerEvent, but, there doesn't seem to be a numerical listing of what the events mean, and, I'm at a loss where to get information about what "Unexpected event type 8" means.

I also noticed that if I remove the channel and side load it fresh, it displays the "resume playing" button the very first time I try to play a video.  

I could use some help in trying to figure this out.
Windows desktop software for creating and managing MRSS, JSON, and FireTV feeds @ https://rrirower.wixsite.com/software. No Programming, JSON or MRSS knowledge required.
0 Kudos
3 Replies
joetesta
Level 10

Re: SampleVideoPlayer - Resume Playing problem

Is this function something you defined?  I don't see it in the Roku docs and surprised it doesn't crash...
GetType()


Also I feel like I remember that removing a sideloaded channel does not necessarily remove its local storage, but I could be mistaken about that.  In general I would suggest you add "print" statements to your code to see what the app is seeing at certain points where it's doing something different than what you expect.
aspiring
0 Kudos
Baradanikto
Level 9

Re: SampleVideoPlayer - Resume Playing problem

I have resolved this problem. And, here's what I learned.

I, like others before me, made the assumption that the Sample Video Player template is bug free. It is not. After digging deeper into the code, I discovered that my problem with the Resume button always showing up was caused by the code. The Sample Video Player code displays the Resume button regardless of the state of the video. In the function, refreshShowDetail(), it adds the button to the screen unconditionally. To resolve this, I had to add a check for the playback position of the last video. My code morphed into:

if PlayStart <> "0" and PlayStart <> invalid then 
        screen.AddButton(1, "resume playing")
    endif    
    screen.AddButton(2, "play from beginning")    
    screen.SetContent(show)
    screen.Show()


I also decided to specify a section, rather than using the default, when reading and writing the playback position to the registry. I called it “PlaybackPostion” and this allowed me to track the reading and writing of this value.

I found that a major stumbling block in debugging this code is the use of print statements as a debugging tool. The existing print statements displayed in the debug console as a mass of strings. This made it difficult to determine where I was in the code at specific times. I reconstructed the print statements to follow this scheme: “source code file name::function name

I placed a print statement at the beginning of each function I was interested in. For example,

print "appDetailScreen::refreshShowDetail"


I then used “tab” on the print statement for all other print commands that originated from within the function. For example, 

print tab(5)">> refreshShowDetail: 'PlayStart' = "; PlayStart


This allowed me to see more quickly and easily where I was in the code since the function execution was delineated by tabs.

Long story short, if you are reading this because you have the same problem, do not assume that the sample code is “clean”. If it doesn't do what you expect, debug the code and assume nothing.
Windows desktop software for creating and managing MRSS, JSON, and FireTV feeds @ https://rrirower.wixsite.com/software. No Programming, JSON or MRSS knowledge required.
0 Kudos
mjhin
Level 7

Re: SampleVideoPlayer - Resume Playing problem

Where can I find this example app?
Can you please post a link to this "SampleVideoPlayer" app?
I can't find it anywhere. Only people talking about it.
0 Kudos