coryatcf
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2012
10:54 AM
Making Simplevideoplayer Try to Access Stream Repeatedly
I would like to adapt the simplevideoplayer script from the SDK so that once a streaming video source is started to play, and then the source stops streaming, the script will continue attempting to reconnect to the stream indefinitely, and not kick back to the Roku home screen. Is this possible?
I am a total newbie to Roku development, and would appreciate any suggestions.
I am a total newbie to Roku development, and would appreciate any suggestions.
12 REPLIES 12

RokuJoel
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2012
11:17 AM
Re: Making Simplevideoplayer Try to Access Stream Repeatedly
Instead of calling displayvideo() if msg.getindex()=1, you would create another function like this:
and then modify the displayvideo function so that unless the user cancels playback, it always try's to play the content, in this case, by returning the value of 1. First modify the function so it returns an integer value:
Then make sure that a 1 is returned in all circumstances except when the user closes the screen:
Hope that helps.
- Joel
function loopvideo() as integer
continue=1
while continue=1
continue=displayvideo()
end while
end function
and then modify the displayvideo function so that unless the user cancels playback, it always try's to play the content, in this case, by returning the value of 1. First modify the function so it returns an integer value:
function displayvideo(args As Dynamic) as integer
Then make sure that a 1 is returned in all circumstances except when the user closes the screen:
while true
msg = wait(0, video.GetMessagePort())
if type(msg) = "roVideoScreenEvent"
if msg.isScreenClosed() then 'ScreenClosed event
print "user cancelled playback, closing video screen"
return 0
else if msg.isPlaybackPosition() then
nowpos = msg.GetIndex()
if nowpos > 0
if abs(nowpos - lastSavedPos) > statusInterval
lastSavedPos = nowpos
end if
end if
else if msg.isRequestFailed()
return 1
else
return 1
end if
end if
end while
return 1
Hope that helps.
- Joel
destruk
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2012
11:35 AM
Re: Making Simplevideoplayer Try to Access Stream Repeatedly
Adding some kind of user feedback might be a good idea so the user knows it's doing something if it's 'retrying stream' or 're-contacting server' to play content.
And I'm not sure if the server host would like being DOS'd with thousands of requests from multiple roku boxes when the stream goes down so it might be a good idea to include a delay between retries (a minute maybe?)
And I'm not sure if the server host would like being DOS'd with thousands of requests from multiple roku boxes when the stream goes down so it might be a good idea to include a delay between retries (a minute maybe?)

RokuJoel
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2012
11:43 AM
Re: Making Simplevideoplayer Try to Access Stream Repeatedly
Good points. Probably even a few seconds delay, 5-15 would be enough to reduce the severity if the server went down, or the stream was not available.
- Joel
- Joel
coryatcf
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2012
11:49 AM
Re: Making Simplevideoplayer Try to Access Stream Repeatedly
Thanks for the responses. How would I code such a delay?

RokuJoel
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2012
12:03 PM
Re: Making Simplevideoplayer Try to Access Stream Repeatedly
function loopvideo() as integer
continue=1
while continue=1
continue=displayvideo()
if continue=1 then
sleep(5000) 'five second delay
end if
end while
end function
coryatcf
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2012
12:06 PM
Re: Making Simplevideoplayer Try to Access Stream Repeatedly
Great, thanks! 🙂
coryatcf
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2012
01:11 PM
Re: Making Simplevideoplayer Try to Access Stream Repeatedly
Joel,
Okay, I'm actually looking at the simplevideoplayer code now, and am guessing that your first code example was showing a concept, not actual code to use for the modification I had in mind?
Here is what I have:
This should take the user right from my channel icon on the home screen to my streaming video, and stay there attempting to play the video stream until the user closes the screen (i.e. presses the "home" button, etc.), right?
Where would I insert the delay?
Okay, I'm actually looking at the simplevideoplayer code now, and am guessing that your first code example was showing a concept, not actual code to use for the modification I had in mind?
Here is what I have:
' ********************************************************************
' ** Simplevideoplayer - adapted by Cory 6-29-2012
' ********************************************************************
Sub Main(args As Dynamic)
displayVideo(" ")
End Sub
'*************************************************************
'** displayVideo()
'*************************************************************
Function displayVideo(args As Dynamic) as integer
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 = [2048] ' >=1.1Mbps = 4 dots
bitrates = [0]
' Live stream from Wowza server
urls = ["http://myserver:1935/live/livestream.sdp/playlist.m3u8"]
qualities = ["SD"]
streamformat = "hls"
title = "Livestream"
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 "user cancelled playback, closing video screen"
return 0
else if msg.isPlaybackPosition() then
nowpos = msg.GetIndex()
if nowpos > 0
if abs(nowpos - lastSavedPos) > statusInterval
lastSavedPos = nowpos
end if
end if
else if msg.isRequestFailed()
return 1
else
return 1
end if
end if
end while
return 1
End Function
This should take the user right from my channel icon on the home screen to my streaming video, and stay there attempting to play the video stream until the user closes the screen (i.e. presses the "home" button, etc.), right?
Where would I insert the delay?
coryatcf
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2012
11:55 AM
Re: Making Simplevideoplayer Try to Access Stream Repeatedly
Okay, I tried this on a Roku now, and no joy... It appears to start to load the video clip, but then stops and kicks back to the home screen. Can anyone see what I am doing wrong here?

RokuMarkn
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2012
12:02 PM
Re: Making Simplevideoplayer Try to Access Stream Repeatedly
What do you see on the debug console?
--Mark
--Mark