Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
doctorew
Level 7

How to switch (or stop) hls stream based on time event

Hi,

I got the sample player script to successfully play an m3u8 we stream throughout the day. However, I want to switch that stream at a particular time to a second stream.

I have my time method working fine (if the app on the private channel begins within either the 1500 or 1600 hour, stream 2 plays, otherwise stream 1 plays.

And in my event loop, I am checking the time. My debug console shows that the time code fires; however, I do not know how to reinitialize the video player:

Tried this:


date = CreateObject("roDateTime")
showtime = date.getHours()'date.getSeconds()
print "|-o-| ts " + videoclip.StreamUrls + " :: " + Str(date.getHours()) + " : " + Str(date.getMinutes()) + " : " + Str(date.getSeconds())
if showtime = 19 Or showtime = 20 then
'if showtime > 19 And showtime < 30 then
print "It's Showtime!!! " + videoclip.StreamUrls + " :: " + Str(date.getHours()) + " : " + Str(date.getMinutes()) + " : " + Str(date.getSeconds())
if videoclip.StreamUrls = "http://path/to/stream_6@156963/master.m3u" then
player.Stop()
video.Close()
videoclip.StreamUrls = "http://path/to/stream_7@156963/master.m3u"
video.SetContent(videoclip)
video.show()
endif


The roku lives in the office (no tv at home Smiley Very Happy), so tomorrow, I will attempt to call the initial method:


date = CreateObject("roDateTime")
showtime = date.getHours()'date.getSeconds()
print "|-o-| ts " + videoclip.StreamUrls + " :: " + Str(date.getHours()) + " : " + Str(date.getMinutes()) + " : " + Str(date.getSeconds())
if showtime = 19 Or showtime = 20 then
'if showtime > 19 And showtime < 30 then
print "It's Showtime!!! " + videoclip.StreamUrls + " :: " + Str(date.getHours()) + " : " + Str(date.getMinutes()) + " : " + Str(date.getSeconds())
if videoclip.StreamUrls = "http://path/to/stream_6@156963/master.m3u" then
player.Stop()
video.Close()
showSpringboardScreen(item)
endif


But if somebody has a better idea, I'll try that, too.

Thanks,

Drew
0 Kudos
1 Reply
doctorew
Level 7

Re: How to switch (or stop) hls stream based on time event

I believe I figured this one out:

In the showSpringboardScreen function:

date = CreateObject("roDateTime")
showtime = date.getMinutes()'date.getSeconds()'date.getHours()'screen.GetMessagePort()
if showtime = 0 or showtime = 10 or showtime = 20 or showtime = 30 or showtime = 40 or showtime = 50 then
fcstream = "http://uri/i/adultswim_7@156963/master.m3u8"
else
fcstream = "http://uri/i/adultswim_6@156963/master.m3u8"
endif
DisplayVideo(fcstream)


displayVideo accepts fcstream as String

Then in the roVideoScreenEvent loop, I check the time (looking at minutes instead of hours to test the functionality)

date = CreateObject("roDateTime")
showtime = date.getMinutes()'date.getSeconds()'date.getHours()'screen.GetMessagePort()
print "|-oo-| ts " + videoclip.StreamUrls + " :: " + Str(date.getHours()) + " : " + Str(date.getMinutes()) + " : " + Str(date.getSeconds())
if showtime = 0 or showtime = 10 or showtime = 20 or showtime = 30 or showtime = 40 or showtime = 50 then
if videoclip.StreamUrls = "http://uri/i/adultswim_6@156963/master.m3u8" then
print "{-o-} player.Stop()"
player.Stop()
print "{-oo-} video.Close()"
video.Close()
print "@@ It's Showtime!! " + videoclip.StreamUrls + " :: " + Str(date.getHours()) + " : " + Str(date.getMinutes()) + " : " + Str(date.getSeconds())
displayVideo("http://uri/i/adultswim_7@156963/master.m3u8")
endif
else if showtime = 5 or showtime = 15 or showtime = 25 or showtime = 35 or showtime = 45 or showtime = 55 then
if videoclip.StreamUrls = "http://uri/i/adultswim_7@156963/master.m3u8" then
print "{-o-} player.Stop()"
player.Stop()
print "{-oo-} video.Close()"
video.Close()
print "@@@It's RerunTime!! " + videoclip.StreamUrls + " :: " + Str(date.getHours()) + " : " + Str(date.getMinutes()) + " : " + Str(date.getSeconds())
displayVideo("http://uri/i/adultswim_6@156963/master.m3u8")
endif
endif


Now that I have the functionality working, I'll look for more elegant / efficient solution.

Thanks,
0 Kudos