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: 
yogamerge
Visitor

Trouble With SetPreviewMode(true)

Hey guys,

I am in the process of building a Free Preview Channel that will upgrade to my current published Pay Channel. I want to use the SetPreviewMode in order to have the Free Preview channel play the first 2 minutes of each video, but I can't seem to get it to work, I read where others had the same issue. Below is my videoscreen.brs Any help would be appreciated. Hoping that I am just missing something simple. Thanks!

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.SetPreviewMode(true)
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.isfullresult()
print "Video Completed Playback Normally"
RegDelete(episode.ContentId)
print "deleted bookmark for playback position"
elseif 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
0 Kudos
11 REPLIES 11
destruk
Binge Watcher

Re: Trouble With SetPreviewMode(true)

You'll need to set the PlayDuration meta-data before screen.setcontent(episode)
PlayDuration - Integer - Optional Playback Max Duration in Seconds - 120 (e.g. 2 minute preview)
0 Kudos
yogamerge
Visitor

Re: Trouble With SetPreviewMode(true)

Thanks, so it would be screen.PlayDuration(120) Yes?
0 Kudos
destruk
Binge Watcher

Re: Trouble With SetPreviewMode(true)

no, episode.PlayDuration(120) since it's metadata for the episode. I wouldn't use this for a commercial project though, as users can fast forward/rewind through the entire file and watch minutes at a time.
It's better to use a different video that is 2 minutes long if you need a 2 minute 'preview'.
0 Kudos
yogamerge
Visitor

Re: Trouble With SetPreviewMode(true)

Thanks, that's good advice. Originally, I was planning on using my already existing preview videos, but thought I would save the server space and avoid the extra xml work, but I had no idea that you could fast forward thru the video with the SetPreviewMode, thanks much
0 Kudos
RokuMarkn
Visitor

Re: Trouble With SetPreviewMode(true)

You can use EnableTrickPlay(false) to disable fast forward etc.

--Mark
0 Kudos
yogamerge
Visitor

Re: Trouble With SetPreviewMode(true)

"RokuMarkn" wrote:
You can use EnableTrickPlay(false) to disable fast forward etc.

--Mark


Thanks Mark, I read that EnableTrickPlay(false) also disables play and pause, this that true or can it be made to only effect fast forward?
0 Kudos
destruk
Binge Watcher

Re: Trouble With SetPreviewMode(true)

EnableTrickPlay doesn't work on firmware <4.9 - so first gen devices would crash if you tried to use it. (have to check firmware)
I did notice first gen devices did get a new firmware update to add the username/password for the dev access screen (3.1). Never got an answer to what other changes were made though.
0 Kudos
RokuJoel
Binge Watcher

Re: Trouble With SetPreviewMode(true)

I believe the only other change to 3.1 firmware was this:
ifListScreen.SetUpBehaviorAtTopRow("exit")
0 Kudos
yogamerge
Visitor

Re: Trouble With SetPreviewMode(true)

Each time I use episode.PlayDuration(120) the videoscreen will not open at anymore, should it be screen.episode.PlayDuration(120)

port = CreateObject("roMessagePort")
screen = CreateObject("roVideoScreen")
screen.SetMessagePort(port)
screen.SetPreviewMode(true)
screen.SetPositionNotificationPeriod(30)
episode.PlayDuration(120)
screen.SetContent(episode)
screen.Show()

each time I add PlayDuration either as episode.PlayDuration or screen.PlayDuration the video screen won't open at all
0 Kudos