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: 
bounce
Level 7

Implementing Resume after 15 Mins

Does anybody have a sample code of implementing resume after 15 mins duration?
My channel was rejected for that issue and I'm not sure if they require a message box asking to resume or not or just pick up where left off.
0 Kudos
5 Replies
destruk
Level 10

Re: Implementing Resume after 15 Mins

I think you're missing their point.  Resume should work for any content with total length longer than 15 minutes.  So if you have a 10-minute video you don't need resume functionality.
You'll need to add a duration to your xml or json feed so your channel knows how long the video is.  And then when drawing the buttons or options on the screen, if it's greater than 15 minutes check for a saved bookmark - if there is a saved bookmark, add the 'resume option' to the screen, and if resume is selected, resume from the save point (which could be within the first minute if it exists), if not just have the play button.  And then if the content is greater than total length of 15 minutes, save a bookmark if the user exits the video before it finishes playing and update the buttons and values of the bookmark field in your content for all open screens.
0 Kudos
bounce
Level 7

Re: Implementing Resume after 15 Mins

I have been struggling with this for a while now. I get that it is for ANY video not just the ones over 15 mins.

First I tried creating a registry entry with the video URL and the time position of every video that is played, put some delimiters in there and tried to split the string, then remerge it all again into one string then save to the registry, which is EXTREMELY clunky. There has to be an easier way to store these bookmarks and the documentation is very vague on it. Anybody have any sample code that they are using that will solve this exhaustive issue for me?
0 Kudos
destruk
Level 10

Re: Implementing Resume after 15 Mins

The problem with using the registry is you have a limited amount of space in Roku to hold data.  So what I've done in the far far past was to keep the last 10 bookmarks in the roku ram and cycle them out so the oldest bookmark is erased and replaced with the newer bookmark.  To get around that issue you can use a database on a server to query for a specific user and read the bookmarks they have, then search for a match to what the roku is currently looking at, or you could download the bookmarks with the content metadata list if your content selection is generated on demand by the server.

For the ancient roku registry code -
Going from lowest callback to highest (most active/least active routines) -
in the video playback routine when it is actually playing a video, you want to store the current position.  Scenegraph sample apps store the bookmarks when the user stops playback themselves, but that doesn't trigger if the box crashes, is unplugged or the power goes out during playback, etc etc. so it might be better top store the position at set intervals.

In your springboard screen:
Initial display of buttons on the screen checks for an existing bookmark:

show=category
screen.ClearButtons()
sec=CreateObject("roRegistrySection",channelname)
found=0
For t=0 To 9
If sec.Exists(CHR(34)+CHR(48+t)+category.title)
found=1
Exit For
End If
Next
If found=1
screen.AddButton(1, "resume playing")
screen.AddButton(2, "play from beginning")
Else
screen.AddButton(1, "play")
End If



When the user selects something to play or resume:

If msg.GetIndex()=1 'Play/Resume Button on screen
Dim b[10]
Dim initialplace[10]
Dim v[10]
Dim bookmarks2[10]

'check registry If program exists
sec=CreateObject("roRegistrySection",channelname)
bookmarks=sec.GetKeyList()
i=0
For Each e In bookmarks 'count the bookmarks
'PrintAny(0, "List(" + itostr(i) + ")= ",e)
b[i]=MID(bookmarks[i],3) 'read episode titles
initialplace[i]=MID(bookmarks[i],2,1) 'read initial placement value
v[i]=RegRead(bookmarks[i],channelname) 'read playback position
bookmarks2[i]=bookmarks[i] 'backup bookmark names
i=i+1
Next

foundz=0
For tz=0 To i-1
If sec.Exists(CHR(34)+CHR(48+tz)+category.title)
foundz=1
category.PlayStart=RegRead(CHR(34)+CHR(48+tz)+category.title,channelname)
Exit For
End If
Next

If foundz=0
If i<10
RegWrite(CHR(34)+CHR(48+tz)+category.title, "0", channelname)
'Print"REGISTRY ENTRY WRITTEN"
'Print CHR(34)+CHR(48+tz)+category.title
'Print"END OF REGISTRY ENTRY WRITTEN"
Else
For tm=0 To i-1
'Print"Deleting ";bookmarks2[tm]
RegDelete(bookmarks2[tm],channelname)
Next
For tm=0 To i-2
b[tm]=b[tm+1]
initialplace[tm]=initialplace[tm+1]
v[tm]=v[tm+1]
'Print"WRITING NEW REGISTRY ";CHR(34)+CHR(48+tm)+b[tm]+" , "+v[tm]
RegWrite(CHR(34)+CHR(48+tm)+b[tm], v[tm], channelname)
Next
RegWrite(CHR(34)+CHR(57)+category.title, "0", channelname)
'Print"WRITING NEW REGISTRY final: ";CHR(34)+CHR(57)+category.title+" , 0"
tz=9
foundz=1
End If
End If
show=category
screen.ClearButtons()
sec=CreateObject("roRegistrySection",channelname)
found=0
For t=0 To 9
If sec.Exists(CHR(34)+CHR(48+t)+category.title)
found=1
Exit For
End If
Next
If found=1
screen.AddButton(1, "resume playing")
screen.AddButton(2, "play from beginning")
Else
screen.AddButton(1, "play")
End If
screen.SetContent(show)
screen.Show()
If foundz=1 showVideoScreen(category,tz)
If foundz=0 showVideoScreen(category,i)
End If



During the video playback --
Function showVideoScreen(episode As Object,t As Integer)
...
screen.SetPositionNotificationPeriod(30)
...
Else If msg.isPlaybackPosition()
nowpos=msg.GetIndex()
RegWrite(CHR(34)+CHR(48+t)+episode.title,nowpos.ToStr(),channelname)


You'll want to delete the bookmark when you get msg.isFullResult() during the video playback, meaning when a user has viewed the full video and update the onscreen button to replace "resume" with "play".  The code for bookmarking is much easier using a server than the roku registry, as the registry can't be counted on to keep the key names in order, or you could probably try using a single key name for everything you need - there was some code posted on the forum to do that somewhere.
0 Kudos
coldrain
Level 7

Re: Implementing Resume after 15 Mins

I've went through this requirement recently for certification, so I create a global unique ID for each video for indexing. Then save the position to register whenever user exit the video and read the register to set bookmark whenever user load a video (I don't care about long or short video now). I could see a problem if user press home to exit instead of press back button, probably I should implements a timer to save it but it's a minor issue to me. I refer to this link for registry read and write (https://github.com/belltown/Roku-NewVid ... /Utils.brs), it does support to limit how many entry in registry so I only store latest 100 video.
Btw, after indexing the video, it's easy to implement the Deep Linking which is also mandated by certification group
0 Kudos
genepensiero
Level 7

Re: Implementing Resume after 15 Mins

"bounce" wrote:
I have been struggling with this for a while now. I get that it is for ANY video not just the ones over 15 mins.

First I tried creating a registry entry with the video URL and the time position of every video that is played, put some delimiters in there and tried to split the string, then remerge it all again into one string then save to the registry, which is EXTREMELY clunky. There has to be an easier way to store these bookmarks and the documentation is very vague on it. Anybody have any sample code that they are using that will solve this exhaustive issue for me?

Did you ever solve this issue? I'm trying to research it myself. 
0 Kudos