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

Auto Play menu in the Roku Script

We are a Roku programmer and are having a problem with occasional packet loss of data on our data upload of our Roku content. This problem lies directly with our ISP and we have been working for weeks to correct this problem. A new fiber is being installed with a 60 day completion time but for now we have plenty of bandwidth up, but an occasional millisecond spike or dip in our data upload of the HLS encode, and the Roku boxes receiving the signal send the channel back to the menu.
Our purpose for the Roku channel is a private channel and direct monitored by the end-users to our channel only. It is for more of a corporate project. The problem is that we and the end user facilities never turn it off, and if we have this network spike on our end, it causes our end users to have to send someone to hit the PLAY button every time this happens because the channel menu comes up. Sometimes at very inopportune moments during the playback.

Is there a way in the script for the channel to tell the Roku signal to “Select” or “Play” the signal automatically in specific time intervals? Say every 30 seconds or 1 minute or something? This would essentially keep the signal going to the Roku boxes without our corporate end users having to send someone to their closed-circuit head-end of the facilities that have the boxes to simply press “play” on the remote whenever there was a signal drop on the upload causing the box to go to menu.

I would think just like when building a DVD, we can script in to auto-play or repeat intervals, that maybe we could do the same with our bright script for our channel? Just not sure if it is possible or how to go about attempting a test.

I have heard there is a way to force the Roku to read from the DVR if it senses signal loss then back to the live steam once it senses it back up. This may be the simpler option?

Any suggestions?
0 Kudos
14 REPLIES 14
belltown
Roku Guru

Re: Auto Play menu in the Roku Script

Does your channel get an isRequestFailed() or isPartialResult() event when the HLS steam is interrupted? If so, you might be able to code the channel so that it automatically restarts the stream. I've been able to do that with my audio player channel so that any interrupted audio streams are automatically restarted without the user having to select 'Play' again. I would think it would be similar for video streams.
0 Kudos
RokuJoel
Binge Watcher

Re: Auto Play menu in the Roku Script

You could pretty easily have a check in the function that calls your video player function like:


returnvalue=-5
while returnvalue=-5
returnvalue=playvideo(video)
end while

so if the video playback fails for any reason other than end of content or user canceling playbak, your video playback function will just start playback again.

you would need to return a value to indicate failure like the -5 above and a different value to indicate intentional end of play.

- Joel
0 Kudos
CorporateTV
Visitor

Re: Auto Play menu in the Roku Script

-RokuJoel

I tried the solution you presented but it did not work. I'm sure do to a mistake on my end.
Below is the code for my video player function, I put the code inside that function, was that right? Am I missing something?


Function displayVideo(args As Dynamic)
print "Displaying video: "
p = CreateObject("roMessagePort")
video = CreateObject("roVideoScreen")
video.setMessagePort(p)

bitrates = [0] ' 0 = no dots, adaptive bitrate
'bitrates = [348] ' <500 Kbps = 1 dot
'bitrates = [664] ' <800 Kbps = 2 dots
'bitrates = [996] ' <1.1Mbps = 3 dots
bitrates = [1500] ' >=1.1Mbps = 4 dots
'bitrates = [0]


'Stream Info
urls = ["http://kitiosdevices-i.akamaihd.net/hls/live/202237/FFE_Roku/iOS/playlist.m3u8"] ' Link of stream, for us, must be an .m3u8
qualities = ["SD"] ' Values for this are "SD" & "HD"
streamformat = "hls" ' Type of stream, we are using HLS.
title = "Family Friendly Entertainment" ' Text shown while stream is loading.
srt = "file://pkg:/source/ffe.srt" ' This .srt is not needed for our channel; however, it must not be deleted or commented out because it is reference below

if type(args) = "roAssociativeArray"
if type(args.url) = "roString" and args.url <> "" then
urls[0] = args.url
end if
if type(args.StreamFormat) = "roString" and args.StreamFormat <> "" then
StreamFormat = args.StreamFormat
end if
if type(args.title) = "roString" and args.title <> "" then
title = args.title
else
title = ""
end if
if type(args.srt) = "roString" and args.srt <> "" then
srt = args.StreamFormat
else
srt = ""
end if
end if

videoclip = CreateObject("roAssociativeArray")
videoclip.StreamBitrates = bitrates
videoclip.StreamUrls = urls
videoclip.StreamQualities = qualities
videoclip.StreamFormat = StreamFormat
videoclip.Title = title
print "srt = ";srt
if srt <> invalid and srt <> "" then
videoclip.SubtitleUrl = srt
end if

video.SetContent(videoclip)
video.show()

lastSavedPos = 0
statusInterval = 10 'position must change by more than this number of seconds before saving

'Code to make channel auto restart
returnvalue=-5
while returnvalue=-5
returnvalue=playvideo(video)
end while

while true
msg = wait(0, video.GetMessagePort())
if type(msg) = "roVideoScreenEvent"
if msg.isScreenClosed() then 'ScreenClosed event
print "Closing video screen"
exit while
else if msg.isPlaybackPosition() then
nowpos = msg.GetIndex()
if nowpos > 10000

end if
if nowpos > 0
if abs(nowpos - lastSavedPos) > statusInterval
lastSavedPos = nowpos
end if
end if
else if msg.isRequestFailed()
print "play failed: "; msg.GetMessage()
else
print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
endif
end if
end while
End Function
0 Kudos
RokuJoel
Binge Watcher

Re: Auto Play menu in the Roku Script

No, I meant the function that calls your videoplayer function is where you would put that code.

In the videoplayer you would just change

else if message.isrequestfailed()
return -5
else if message.isfullresult()
return -1
end if


down near the bottom of the function.

so undo what you did, then modify your video function as above. Assuming you are using simplevideoplayer, which it looks like you are, then you would modify function show springboard screen as follows:

from

 else if msg.isButtonPressed()
print "Button pressed: "; msg.GetIndex(); " " msg.GetData()
if msg.GetIndex() = 1
displayVideo("")
else if msg.GetIndex() = 2
return true
endif
else


to:

 else if msg.isButtonPressed()
print "Button pressed: "; msg.GetIndex(); " " msg.GetData()
if msg.GetIndex() = 1

returnvalue=-5
while returnvalue=-5
returnvalue=displayVideo("")
end while

else if msg.GetIndex() = 2
return true
endif
else
0 Kudos
CorporateTV
Visitor

Re: Auto Play menu in the Roku Script

-Joel
I updated my code with the snippets that you provided, see below.
Another problem I'm having now is that when i upload the code to the ROKU box and view in "Side Developer Mode," the stream will play. But when I package, and upload it to ROKU and preview it, it will show the loading screen for a couple seconds before returning me back to the ROKU home screen.

Any Idea what could be causing that. After all, this is the same code that was running before and worked.

Thanks for you help!


'*************************************************************
'** showSpringboardScreen()
'*************************************************************

Function showSpringboardScreen(item as object) As Boolean
port = CreateObject("roMessagePort")
screen = CreateObject("roSpringboardScreen")

print "showSpringboardScreen"

screen.SetMessagePort(port)
screen.AllowUpdates(false)
if item <> invalid and type(item) = "roAssociativeArray"
screen.SetContent(item)
endif

screen.SetDescriptionStyle("generic") 'audio, movie, video, generic
' generic+episode=4x3,
screen.ClearButtons()
screen.AddButton(1,"Play Live Stream")
screen.AddButton(2,"Go Back")
screen.SetStaticRatingEnabled(false)
screen.AllowUpdates(true)
screen.Show()

downKey=3
selectKey=6
while true
msg = wait(0, screen.GetMessagePort())
if type(msg) = "roSpringboardScreenEvent"
if msg.isScreenClosed()
print "Screen closed"
exit while
else if msg.isButtonPressed()
print "Button pressed: "; msg.GetIndex(); " " msg.GetData()
if msg.GetIndex() = 1

returnvalue=-5
while returnvalue=-5
returnvalue=displayVideo("")
end while

else if msg.GetIndex() = 2
return true
endif
else
print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
endif
else
print "wrong type.... type=";msg.GetType(); " msg: "; msg.GetMessage()
endif
end while


return true
End Function


'*************************************************************
'** displayVideo()
'*************************************************************

Function displayVideo(args As Dynamic)
print "Displaying video: "
p = CreateObject("roMessagePort")
video = CreateObject("roVideoScreen")
video.setMessagePort(p)

bitrates = [0] ' 0 = no dots, adaptive bitrate
'bitrates = [348] ' <500 Kbps = 1 dot
'bitrates = [664] ' <800 Kbps = 2 dots
'bitrates = [996] ' <1.1Mbps = 3 dots
bitrates = [1500] ' >=1.1Mbps = 4 dots
'bitrates = [0]

'Swap the commented values below to play different video clips...

' Family Friendly Entertainment Stream Info
urls = ["http://kitiosdevices-i.akamaihd.net/hls/live/202237/FFE_Roku/iOS/playlist.m3u8"]
qualities = ["SD"]
streamformat = "hls"
title = "Family Friendly Entertainment"
srt = "file://pkg:/source/craigventer.srt"

if type(args) = "roAssociativeArray"
if type(args.url) = "roString" and args.url <> "" then
urls[0] = args.url
end if
if type(args.StreamFormat) = "roString" and args.StreamFormat <> "" then
StreamFormat = args.StreamFormat
end if
if type(args.title) = "roString" and args.title <> "" then
title = args.title
else
title = ""
end if
if type(args.srt) = "roString" and args.srt <> "" then
srt = args.StreamFormat
else
srt = ""
end if
end if

videoclip = CreateObject("roAssociativeArray")
videoclip.StreamBitrates = bitrates
videoclip.StreamUrls = urls
videoclip.StreamQualities = qualities
videoclip.StreamFormat = StreamFormat
videoclip.Title = title
print "srt = ";srt
if srt <> invalid and srt <> "" then
videoclip.SubtitleUrl = srt
end if

video.SetContent(videoclip)
video.show()

lastSavedPos = 0
statusInterval = 10 'position must change by more than this number of seconds before saving

while true
msg = wait(0, video.GetMessagePort())
if type(msg) = "roVideoScreenEvent"
if msg.isScreenClosed() then 'ScreenClosed event
print "Closing video screen"
exit while
else if msg.isPlaybackPosition() then
nowpos = msg.GetIndex()
if nowpos > 10000

end if
if nowpos > 0
if abs(nowpos - lastSavedPos) > statusInterval
lastSavedPos = nowpos
end if
end if
else if message.isrequestfailed()
return -5
else if message.isfullresult()
return -1
end if
end if
end while
End Function
0 Kudos
RokuJoel
Binge Watcher

Re: Auto Play menu in the Roku Script

When you side-load and the stream plays, does your brightscript stop running and bring you back to the debugger prompt, even though the video is playing?

In public or private channel, if the code stops running, the channel exits instead of becoming unresponsive to clicks.

Joel
0 Kudos
CorporateTV
Visitor

Re: Auto Play menu in the Roku Script

When you side-load and the stream plays, does your brightscript stop running and bring you back to the debugger prompt, even though the video is playing?


It does not bring me back to any debugger that I am aware of. How would I know?
0 Kudos
RokuJoel
Binge Watcher

Re: Auto Play menu in the Roku Script

When developing and testing a channel, you should be connected to your Roku player via telnet connection on port 8085. Best bet on a pc is to download Putty and use it (select the telnet setting) to connect to your device. There is also a pure telnet version called PuttyTel if you don't want to be bothered with other "swiss army knife" functions.

You can also install window's built-in telnet but it is not as easy to use as Putty.

On a mac, just load Terminal and type:

telnet <ip address of my device> 8085

For example, if your device is on 192.168.1.54 then you would type:

telnet 192.168.1.54 8085

and hit the enter key.

- Joel
0 Kudos
CorporateTV
Visitor

Re: Auto Play menu in the Roku Script

Joel,

Thanks for clarifying the debugging thing.

In regards for the auto restart that we are trying to get working. There is something definitely not right with the script that you have helped us develop.

Here is what the code is:

' ********************************************************************
' ** Sample PlayVideo App
' ** Copyright (c) 2009 Roku Inc. All Rights Reserved.
' ********************************************************************

Sub Main(args As Dynamic)
'initialize theme attributes like titles, logos and overhang color
initTheme()

if type(args) = "roAssociativeArray" and type(args.url) = "roString" then
displayVideo(args)
end if
print "Type args = "; type(args)
print "Type args.url = "; type(args.url)

'has to live for the duration of the whole app to prevent flashing
'back to the roku home screen.
screenFacade = CreateObject("roPosterScreen")
screenFacade.show()

item = { ContentType:"episode"
SDPosterUrl:"file://pkg:/images/BigBuckBunny.jpg"
HDPosterUrl:"file://pkg:/images/BigBuckBunny.jpg"
IsHD:false
HDBranded:true
ShortDescriptionLine1:"The Music Channel"
ShortDescriptionLine2:""
Description:"Playing the best in Southern Gospel and Christian Country Music, 24 hours a day!"
Rating:"NR"
StarRating:"80"
'Length:999999999
Categories:["Music","Religious"]
Title:"Family Friendly Entertainment"
}

showSpringboardScreen(item) 'uncomment this line to see the BigBuckBunny example

'exit the app gently so that the screen doesn't flash to black
screenFacade.showMessage("")
sleep(25)
End Sub

'*************************************************************
'** Set the configurable theme attributes for the application
'**
'** Configure the custom overhang and Logo attributes
'*************************************************************

Sub initTheme()

app = CreateObject("roAppManager")
theme = CreateObject("roAssociativeArray")

theme.OverhangPrimaryLogoOffsetSD_X = "72"
theme.OverhangPrimaryLogoOffsetSD_Y = "15"
theme.OverhangSliceSD = "pkg:/images/Overhang_BackgroundSlice_SD43.png"
theme.OverhangPrimaryLogoSD = "pkg:/images/Logo_Overhang_SD43.png"

theme.OverhangPrimaryLogoOffsetHD_X = "123"
theme.OverhangPrimaryLogoOffsetHD_Y = "20"
theme.OverhangSliceHD = "pkg:/images/Overhang_BackgroundSlice_HD.png"
theme.OverhangPrimaryLogoHD = "pkg:/images/Logo_Overhang_HD.png"

'this is an optional theme attribute. the default subtitle color is yellow.
theme.SubtitleColor = "#dc00dc"

app.SetTheme(theme)

End Sub


'*************************************************************
'** showSpringboardScreen()
'*************************************************************

Function showSpringboardScreen(item as object) As Boolean
port = CreateObject("roMessagePort")
screen = CreateObject("roSpringboardScreen")

print "showSpringboardScreen"

screen.SetMessagePort(port)
screen.AllowUpdates(false)
if item <> invalid and type(item) = "roAssociativeArray"
screen.SetContent(item)
endif

screen.SetDescriptionStyle("generic") 'audio, movie, video, generic
' generic+episode=4x3,
screen.ClearButtons()
screen.AddButton(1,"Play Live Stream")
screen.AddButton(2,"Go Back")
screen.SetStaticRatingEnabled(false)
screen.AllowUpdates(true)
screen.Show()

downKey=3
selectKey=6
while true
msg = wait(0, screen.GetMessagePort())
if type(msg) = "roSpringboardScreenEvent"
if msg.isScreenClosed()
print "Screen closed"
exit while
else if msg.isButtonPressed()
print "Button pressed: "; msg.GetIndex(); " " msg.GetData()
if msg.GetIndex() = 1

returnvalue=-5
while returnvalue=-5
returnvalue=displayVideo("")
end while

else if msg.GetIndex() = 2
return true
endif
else
print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
endif
else
print "wrong type.... type=";msg.GetType(); " msg: "; msg.GetMessage()
endif
end while


return true
End Function


'*************************************************************
'** displayVideo()
'*************************************************************

Function displayVideo(args As Dynamic)
print "Displaying video: "
p = CreateObject("roMessagePort")
video = CreateObject("roVideoScreen")
video.setMessagePort(p)

bitrates = [0] ' 0 = no dots, adaptive bitrate
'bitrates = [348] ' <500 Kbps = 1 dot
'bitrates = [664] ' <800 Kbps = 2 dots
'bitrates = [996] ' <1.1Mbps = 3 dots
bitrates = [1500] ' >=1.1Mbps = 4 dots
'bitrates = [0]

'Swap the commented values below to play different video clips...

' Stream Info
urls = ["http://kitiosdevices-i.akamaihd.net/hls/live/202237/FFE_Roku/iOS/playlist.m3u8"]
qualities = ["SD"]
streamformat = "hls"
title = "The Music Channel"
srt = "file://pkg:/source/craigventer.srt"

if type(args) = "roAssociativeArray"
if type(args.url) = "roString" and args.url <> "" then
urls[0] = args.url
end if
if type(args.StreamFormat) = "roString" and args.StreamFormat <> "" then
StreamFormat = args.StreamFormat
end if
if type(args.title) = "roString" and args.title <> "" then
title = args.title
else
title = ""
end if
if type(args.srt) = "roString" and args.srt <> "" then
srt = args.StreamFormat
else
srt = ""
end if
end if

videoclip = CreateObject("roAssociativeArray")
videoclip.StreamBitrates = bitrates
videoclip.StreamUrls = urls
videoclip.StreamQualities = qualities
videoclip.StreamFormat = StreamFormat
videoclip.Title = title
print "srt = ";srt
if srt <> invalid and srt <> "" then
videoclip.SubtitleUrl = srt
end if

video.SetContent(videoclip)
video.show()

lastSavedPos = 0
statusInterval = 10 'position must change by more than this number of seconds before saving

while true
msg = wait(0, video.GetMessagePort())
if type(msg) = "roVideoScreenEvent"
if msg.isScreenClosed() then 'ScreenClosed event
print "Closing video screen"
exit while
else if msg.isPlaybackPosition() then
nowpos = msg.GetIndex()
if nowpos > 10000

end if
if nowpos > 0
if abs(nowpos - lastSavedPos) > statusInterval
lastSavedPos = nowpos
end if
end if
else if message.isrequestfailed()
return -5
else if message.isfullresult()
return -1
end if
end if
end while
End Function



Here is what the debugger is giving us:

*** ERROR compiling /pkg:/source/appMain.brs:
Syntax Error. (compile error &h02) in ...4pfNw/pkg:/source/appMain.brs(21)
Syntax Error. (compile error &h02) in ...4pfNw/pkg:/source/appMain.brs(23)
Syntax Error. (compile error &h02) in ...4pfNw/pkg:/source/appMain.brs(24)
Syntax Error. (compile error &h02) in ...4pfNw/pkg:/source/appMain.brs(25)
Syntax Error. (compile error &h02) in ...4pfNw/pkg:/source/appMain.brs(26)
------ Running ------
Type args = roAssociativeArray
Type args.url = Invalid
showSpringboardScreen
Screen closed
Leaked bsc instances:
roAssociativeArray refcnt= 1 addr=0x5bf357b0
roString refcnt= 1 addr=0x5bf4c908 [auto-run-dev]
------ Running ------
Type args = roAssociativeArray
Type args.url = Invalid
showSpringboardScreen
Button pressed: 1 0
Displaying video:
srt = file://pkg:/source/craigventer.srt
BrightScript Micro Debugger.
Enter any BrightScript statement, debug commands, or HELP.

Current Function:
134: Function displayVideo(args As Dynamic)
135: print "Displaying video: "
136: p = CreateObject("roMessagePort")
137: video = CreateObject("roVideoScreen")
138: video.setMessagePort(p)
139:
140: bitrates = [0] ' 0 = no dots, adaptive bitrate
141: 'bitrates = [348] ' <500 Kbps = 1 dot
142: 'bitrates = [664] ' <800 Kbps = 2 dots
143: 'bitrates = [996] ' <1.1Mbps = 3 dots
144: bitrates = [1500] ' >=1.1Mbps = 4 dots
145: 'bitrates = [0]
146:
147: 'Swap the commented values below to play different video clips...
148:
149: ' Stream Info
150: urls = ["http://kitiosdevices-i.akamaihd.net/hls/live/202237/FFE_Roku/iOS/playlist.m3u8"]
151: qualities = ["SD"]
152: streamformat = "hls"
153: title = "The Music Channel"
154: srt = "file://pkg:/source/craigventer.srt"
155:
156: if type(args) = "roAssociativeArray"
157: if type(args.url) = "roString" and args.url <> "" then
158: urls[0] = args.url
159: end if
160: if type(args.StreamFormat) = "roString" and args.StreamFormat <> "" then
161: StreamFormat = args.StreamFormat
162: end if
163: if type(args.title) = "roString" and args.title <> "" then
164: title = args.title
165: else
166: title = ""
167: end if
168: if type(args.srt) = "roString" and args.srt <> "" then
169: srt = args.StreamFormat
170: else
171: srt = ""
172: end if
173: end if
174:
175: videoclip = CreateObject("roAssociativeArray")
176: videoclip.StreamBitrates = bitrates
177: videoclip.StreamUrls = urls
178: videoclip.StreamQualities = qualities
179: videoclip.StreamFormat = StreamFormat
180: videoclip.Title = title
181: print "srt = ";srt
182: if srt <> invalid and srt <> "" then
183: videoclip.SubtitleUrl = srt
184: end if
185:
186: video.SetContent(videoclip)
187: video.show()
188:
189: lastSavedPos = 0
190: statusInterval = 10 'position must change by more than this number of seconds before saving
191:
192: while true
193: msg = wait(0, video.GetMessagePort())
194: if type(msg) = "roVideoScreenEvent"
195: if msg.isScreenClosed() then 'ScreenClosed event
196: print "Closing video screen"
197: exit while
198: else if msg.isPlaybackPosition() then
199: nowpos = msg.GetIndex()
200: if nowpos > 10000
201:
202: end if
203: if nowpos > 0
204: if abs(nowpos - lastSavedPos) > statusInterval
205: lastSavedPos = nowpos
206: end if
207: end if
208: else if message.isrequestfailed()
209: return -5
210: else if message.isfullresult()
211: return -1
212: end if
213: end if
214: end while
215: End Function
'Dot' Operator attempted with invalid BrightScript Component or interface reference. (runtime error &hec) in ...QiB4p/pkg:/source/appMain.brs(208)

208: else if message.isrequestfailed()
Backtrace:
Function displayvideo(args As ) As
file/line: /tmp/plugin/ACAA...QiB4p/pkg:/source/appMain.brs(208)
Function showspringboardscreen(item As <uninitialized>) As Boolean
file/line: /tmp/plugin/ACAA...QiB4p/pkg:/source/appMain.brs(111)
Function main(args As ) As
file/line: /tmp/plugin/ACAA...QiB4p/pkg:/source/appMain.brs(36)

Local Variables:
args &h0100 String (VT_STR_CONST) val:
global &h0020 rotINTERFACE:ifGlobal
m &h0010 bsc:roAssociativeArray, refcnt=4
p &h0010 bsc:roMessagePort, refcnt=2
video &h0010 bsc:roVideoScreen, refcnt=1
bitrates &h0010 bsc:roArray, refcnt=2
urls &h0010 bsc:roArray, refcnt=2
qualities &h0010 bsc:roArray, refcnt=2
streamformat &h0100 String (VT_STR_CONST) val:hls
title &h0100 String (VT_STR_CONST) val:Family Friendly Entertainment
srt &h0100 String (VT_STR_CONST) val:file://pkg:/source/craigventer.srt
videoclip &h0010 bsc:roAssociativeArray, refcnt=1
lastsavedpos &h0002 Integer val:0
statusinterval &h0002 Integer val:10
msg &h0010 bsc:roVideoScreenEvent, refcnt=1
nowpos &h0000 <uninitialized> val:Uninitialized
message &h0000 <uninitialized> val:Uninitialized
BrightScript Debugger>


The video will play in side mode, but the application will not even load when I package and upload it to ROKU. Any idea on what I'm doing wrong?
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.