Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Roku Employee
Roku Employee

Re: HLS auto-switch

Here's a simplified version of simplevideoplayer code: that should work to stream a live stream:


sub main()
print "Displaying video: "
p = CreateObject("roMessagePort")
video = CreateObject("roVideoScreen")
video.setMessagePort(p)

videoclip = CreateObject("roAssociativeArray")
videoclip.StreamBitrates = [0]

videoclip.StreamUrls = ["http://myserver.com/mylivestream.m3u8"]

di = CreateObject("roDeviceInfo")
if di.GetDisplayType() = "HDTV" then
videoclip.streamqualities=["HD"]
else
videoclip.streamqualities=["SD"]
end if

videoclip.StreamFormat = "hls"
videoclip.Title = "my awesome live stream"
videoclip.SubtitleUrl = ""
videoclip.switchingstrategy="full-adaptation"

video.SetContent(videoclip)
video.show()

lastSavedPos = 0
statusInterval = 10

while true
msg = wait(0, video.GetMessagePort())
if type(msg) = "roVideoScreenEvent"
if msg.isScreenClosed() then 'ScreenClosed event
print "Closing video screen"
return
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 sub
0 Kudos
Level 7

Re: HLS auto-switch

Hello everyone. After reading this post, its clear to me that Roku2 can play multibitrate HLS playlist. However, I am new to Roku and I don't understand how to make this happen. I am using Wowza v3.1.2 and my HLS adaptive bit rate URL (playlist.m3u8) works fine on Apple iphone, ipad and android devices. However, the same URL is not working on Roku 2. One more point, single stream (single bit rate) from same Wowza server works fine on this same Roku 2. What am i doing wrong or what do i need to do, to publish the multi-bitrate HLS playlist to a Roku 2.

Thank you for your assistance.
Regards
Felix
0 Kudos
Level 7

Re: HLS auto-switch

"videodev" wrote:
"TheEndless" wrote:
Make sure you are setting the SwitchingStrategy value. A bug was introduced a few firmwares ago that would prevent HLS from switching to a higher bitrate if the SwitchingStrategy wasn't set. I don't know if that bug was ever fixed, but it's best to always set that value.


Thank you. It worked. I am using SwitchingStrategy as "full-adaptation".

Another question - As I mentioned above, I am using HLS streams from Wowza server, which has 6 variants from 150k to 3600k. I read in the documentation that, the dots/HD symbol is not displayed, if the stream is HLS. Is there any way to display HD if any of the variant is of HD quality?

I am using "0" as StreamBitrates in XML.

Any other suggestions for quick switching/buffering/scrubbling?

Thank you!


I am having the same issue like the creator of this thread but since I am very new to the topic, I could not figure the solution for the problem from the answers.

What is the code for the "SwitchingStrategy"? How do I do that?
I also point HLS streams to the playlist.m3u8 file and the Roku insists on choosing the stream with the lowest bitrate Smiley Sad Thanks in advance!
0 Kudos
Level 8

Re: HLS auto-switch

Go to sdkdocs.roku.com and search for "SwitchingStrategy".

--Mark
0 Kudos
Level 7

Re: HLS auto-switch

So I add a line
<SwitchingStrategy>full-adaption</SwitchingStrategy> in between the <media></media> tag?
0 Kudos
Level 8

Re: HLS auto-switch

That code will be placed in the showFeed.brs if using videoplayer. Search for the first line here and add the rest.

If item.StreamFormat="" 'set default streamFormat to mp4 if doesn't exist in xml
item.StreamFormat="mp4"
End If
If item.StreamFormat="hls"
item.SwitchingStrategy="full-adaptation"
End If
0 Kudos
Level 7

Re: HLS auto-switch

That works great, thank you!

Is there any way to use those commands in the XML-File with tags?
I am talking about the commands on the SDK page http://sdkdocs.roku.com/display/sdkdoc42/Content+Meta-Data

I am asking because I would like to know if I really always have to make a package and install it on the Roku or if I can just change it on the fly.
0 Kudos
Roku Employee
Roku Employee

Re: HLS auto-switch

if you add a tag to your XML:


<SwitchingStrategh>full-adaptation</SwitchingStrategy>	


and a line to your xml parser in ShowFeed.brs (assuming your channel is based on videoplayer example):

    item.SwitchingStrategy=validstr(curshow.switchingStrategy.gettext())


probably should put that after the item.StreamFormat= line.

Then you should be able to control which switching strategy is used by your channel on a per-item basis.

You can put whatever you want in your XML, as long as it is valid xml, and you have an xml parser to decode it, you can control your channel completely from your server.

- Joel
0 Kudos
Level 8

Re: HLS auto-switch

"RokuJoel" wrote:
<SwitchingStrategh>full-adaptation</SwitchingStrategy>
^
Do watch out for typos though! Smiley Happy
Remoku.tv - A free web app for Roku Remote Control!
Want to control your Roku from nearly any phone, computer or tablet? Get started at http://help.remoku.tv
by Apps4TV - Applications for television and beyond: http://www.apps4tv.com
0 Kudos
Level 7

Re: HLS auto-switch

"RokuJoel" wrote:
if you add a tag to your XML:


<SwitchingStrategh>full-adaptation</SwitchingStrategy>	


and a line to your xml parser in ShowFeed.brs (assuming your channel is based on videoplayer example):

    item.SwitchingStrategy=validstr(curshow.switchingStrategy.gettext())


probably should put that after the item.StreamFormat= line


Can I follow that pattern for the other tags also?

I mean adding the code
<XYZ>whatever</XYZ>
to my XML file

and the code
[code]item.XYZ=validstr(curshow.XYZ.gettext())

to the showfeed.brs? or would that be different for the different tags?
Of course XYZ is a tag from the attributes column on http://sdkdocs.roku.com/display/sdkdoc/ ... +Meta-Data
0 Kudos