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

Timer to stop live feed

Hello,
I need some direction in how to stop play once started with the timer


if msg.GetIndex() = 1
m.timer=createobject("roTimeSpan")
m.timer.mark()
while true
if m.timer.totalseconds < 20 then
PlayStart = 0
else
return showIndex
end if
end while


I thought this would work ... but it isn't ..... any direction in this would be greatly appreciated

Thanks
0 Kudos
9 REPLIES 9
RokuMarkn
Visitor

Re: Timer to stop live feed

You should add the timer handling code to the event loop which handles the video. Change the wait to a timed wait, if it isn't already, and periodically check the elapsed time on the timer.

--Mark
0 Kudos
kooljay68
Visitor

Re: Timer to stop live feed

so does that mean the timer has to be part of the appVideoScreen.brs loop then?
0 Kudos
RokuMarkn
Visitor

Re: Timer to stop live feed

Yes, that's correct.

--Mark
0 Kudos
kooljay68
Visitor

Re: Timer to stop live feed

ok ... I think I know where it goes now ... but I am a little lost on how I would change the different stop times if I wanted too ... which page would I have to send that command from ?
0 Kudos
kooljay68
Visitor

Re: Timer to stop live feed

OK ... I added this to the video page and it does nothing .... I guess I am really lost on what I am supposed to do here - Please help.


screen.Show()

m.timer=createobject("roTimeSpan")
m.timer.mark()

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

while true
msg = wait(0, port)

if m.timer.totalseconds > 60 then
print "End Preview: "; msg.GetIndex(); " " msg.GetData()
end if
0 Kudos
destruk
Streaming Star

Re: Timer to stop live feed

A wait timeout of 0 will wait forever, until a message is received.
You want to change that to an incremental timeout like
msg = wait(1000, port)

That way it will run through the loop at least once per second all by itself.
0 Kudos
kooljay68
Visitor

Re: Timer to stop live feed

OK .. I changed that like you say ... but I must still be off the mark ... because it will not kick out of the video ? Here is all of the code for the page ... maybe that will help



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()

m.timer=createobject("roTimeSpan")
m.timer.mark()

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

while true
msg = wait(1000, port)

if m.timer.totalseconds > 60 then
print "End Preview: "; msg.GetIndex(); " " msg.GetData()
end if

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






0 Kudos
TheEndless
Channel Surfer

Re: Timer to stop live feed

"kooljay68" wrote:
OK .. I changed that like you say ... but I must still be off the mark ... because it will not kick out of the video ? Here is all of the code for the page ... maybe that will help



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()

m.timer=createobject("roTimeSpan")
m.timer.mark()

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

while true
msg = wait(1000, port)

if m.timer.totalseconds > 60 then
print "End Preview: "; msg.GetIndex(); " " msg.GetData()
end if

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

You don't have code in there to exit the video. Right now, it will likely crash after 60 seconds, because you're not checking the validity of msg. That aside, at best it should print the message "End Preview..." to the console (every second) after it reaches 60 seconds, but it won't exit the video, because you're not closing the screen.

BTW, if your goal is to just show a portion of the video as a preview, you should be able to use the PlayDuration content metadata attribute, instead of timing it in code. Alternatively, you could kill the video based on the playback position notification.
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)
0 Kudos
kooljay68
Visitor

Re: Timer to stop live feed

Sweet ... I used PlayDuration and it worked like a charm .... Thank you for the input.
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.