coryatcf
Visitor

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.
Tags (1)
0 Kudos
12 REPLIES 12
RokuJoel
Binge Watcher

Re: Making Simplevideoplayer Try to Access Stream Repeatedly

Instead of calling displayvideo() if msg.getindex()=1, you would create another function like this:


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
Tags (1)
0 Kudos
destruk
Streaming Star

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?)
Tags (1)
0 Kudos
RokuJoel
Binge Watcher

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
Tags (1)
0 Kudos
coryatcf
Visitor

Re: Making Simplevideoplayer Try to Access Stream Repeatedly

Thanks for the responses. How would I code such a delay?
Tags (1)
0 Kudos
RokuJoel
Binge Watcher

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
Tags (1)
0 Kudos
coryatcf
Visitor

Re: Making Simplevideoplayer Try to Access Stream Repeatedly

Great, thanks! 🙂
Tags (1)
0 Kudos
coryatcf
Visitor

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:

' ********************************************************************
' ** 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?
Tags (1)
0 Kudos
coryatcf
Visitor

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?
Tags (1)
0 Kudos
RokuMarkn
Visitor

Re: Making Simplevideoplayer Try to Access Stream Repeatedly

What do you see on the debug console?

--Mark
Tags (1)
0 Kudos
Community is Temporarily in Read-Only Mode!

We’re upgrading Roku Community to bring you a faster, more mobile-friendly experience. You may notice limited functionality or read-only access during this time. You will not be able to log in or post new comments or kudos during this time. Read more here.

Planned Downtime:
Community will be unavailable for up to 24–48 hours during the upgrade window during the week of May 12 and you may notice reduced functionality. In the meantime, for additional assistance, visit our Support Site.

Thanks for your patience — we’re excited to share what’s next!