# HLS auto-switch

**URL:** <https://forum.developer.roku.com/t/hls-auto-switch/2662>\
**Category:** Archived\
**Tags:** roku-developer-program\
**Created:** [September 21, 2012, 6:41pm UTC](https://forum.developer.roku.com/t/hls-auto-switch/2662 "2012-09-21T18:41:49Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ionatan](https://avatars.discourse-cdn.com/v4/letter/i/3bc359/32.png) [@ionatan](https://forum.developer.roku.com/u/ionatan)\
**Post date:** [September 21, 2012, 6:41pm UTC](https://forum.developer.roku.com/t/hls-auto-switch/2662/1 "2012-09-21T18:41:49Z")

</div>

Would this work on a Roku Channel? Is working auto-switch with hls? Thanks!

```auto
<media>
<streamQuality>SD</streamQuality>
<streamBitrate>0</streamBitrate>
<streamUrl>http://server...../streamSD/playlist.m3u8</streamUrl>
</media>
<media>
<streamQuality>HD</streamQuality>
<streamBitrate>0</streamBitrate>
<streamUrl>http://server...../streamHD/playlist.m3u8</streamUrl>
</media>

```

---

<div class="post-metadata">

**Author:** ![RokuJoel](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@RokuJoel](https://forum.developer.roku.com/u/RokuJoel)\
**Post date:** [September 21, 2012, 9:02pm UTC](https://forum.developer.roku.com/t/hls-auto-switch/2662/2 "2012-09-21T21:02:43Z")

</div>

You would have to have something to parse it like:

```auto

if xml.parse(data)
videos=[]
for each object in xml.media
video={}
video.streamquality=[object.streamquality.gettext()]
video.streambitrate=[object.streambitrate.gettext().toint()]
video.streamurl=[object.streamurl.gettext]
videos.push(video)
end for
end if 
video.SwitchingStrategy="full-adaptation"

```

and then feed that into your video playback function. But you should ideally have more data than just the videos, such as title, shortdescriptionLine1 and thumbnail images.

also, you need to check the device mode - if SDTV mode you would override the streamQuality with [“SD”] or playback will fail in SDTV mode.

- Joel

---

<div class="post-metadata">

**Author:** ![RokuMarkn](https://avatars.discourse-cdn.com/v4/letter/r/ac8455/32.png) [@RokuMarkn](https://forum.developer.roku.com/u/RokuMarkn)\
**Post date:** [September 21, 2012, 10:07pm UTC](https://forum.developer.roku.com/t/hls-auto-switch/2662/3 "2012-09-21T22:07:36Z")

</div>

Actually for HLS, you should NOT specify multiple URLs. You should put the URLs for the different streams in the top-level m3u8 as specified by the HLS spec, and pass that one URL to the video player. This allows the player to dynamically switch bitrates.

–Mark

---

<div class="post-metadata">

**Author:** ![ionatan](https://avatars.discourse-cdn.com/v4/letter/i/3bc359/32.png) [@ionatan](https://forum.developer.roku.com/u/ionatan)\
**Post date:** [September 24, 2012, 9:03am UTC](https://forum.developer.roku.com/t/hls-auto-switch/2662/4 "2012-09-24T09:03:33Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![videodev](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@videodev](https://forum.developer.roku.com/u/videodev)\
**Post date:** [September 30, 2012, 9:06pm UTC](https://forum.developer.roku.com/t/hls-auto-switch/2662/5 "2012-09-30T21:06:44Z")

</div>

Hello,

I am new to ROKU and using SampleVideoPlayer code to test my HLS streams. Even though, I have 6 different bit rates in my playlist.m3u8 file, ROKU picks the low quality stream and is not switching to high bit rate. I have enough internet bandwidth to use high quality stream.

Below is the section of code, which loads the streams from XML file:

```auto

e = curShow.media[0]
	if e <> invalid then
		item.StreamBitrates.Push(strtoi(validstr(e.streamBitrate.GetText())))
		item.StreamQualities.Push(validstr(e.streamQuality.GetText()))
		item.StreamUrls.Push(validstr(e.streamUrl.GetText()))
	endif

```

Below is the XML for an item:

```auto

<item sdImg="http://xxxzzz.com/images/gh.png" hdImg="http://xxxzzz.com/images/gh.png">
    <title>My Test Stream 2</title>
    <contentId>10053</contentId>
    <contentType>Movies</contentType>
    <contentQuality>SD</contentQuality>
    <streamFormat>hls</streamFormat>
    <media>
      <streamQuality>SD</streamQuality>
      <streamBitrate>0</streamBitrate>
      <streamUrl>http://yyyzzz.com/playlist.m3u8</streamUrl>
    </media>
    <synopsis></synopsis>
    <subtitleUrl></subtitleUrl>
    <genres></genres>
    <runtime>9600</runtime>
    <hdBifUrl></hdBifUrl>
  </item>

```

And below is the streams in playlist.m3u8 file:

```auto

#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=200000
http://yyyzzz.com/mp4:n_150k.mp4/playlist.m3u8?wowzasessionid=1937835477
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=400000
http://yyyzzz.com/mp4:n_300k.mp4/playlist.m3u8?wowzasessionid=1937835477
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=600000
http://yyyzzz.com/mp4:n_500k.mp4/playlist.m3u8?wowzasessionid=1937835477
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1000000
http://yyyzzz.com/mp4:n_800k.mp4/playlist.m3u8?wowzasessionid=1937835477
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1500000
http://yyyzzz.com/mp4:n_1200k.mp4/playlist.m3u8?wowzasessionid=1937835477
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2300000
http://yyyzzz.com/mp4:n_1800k.mp4/playlist.m3u8?wowzasessionid=1937835477

```

Any suggestions?

Thank you!

---

<div class="post-metadata">

**Author:** ![TheEndless](https://avatars.discourse-cdn.com/v4/letter/t/ec9cab/32.png) [@TheEndless](https://forum.developer.roku.com/u/TheEndless)\
**Post date:** [September 30, 2012, 9:18pm UTC](https://forum.developer.roku.com/t/hls-auto-switch/2662/6 "2012-09-30T21:18:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![videodev](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@videodev](https://forum.developer.roku.com/u/videodev)\
**Post date:** [September 30, 2012, 9:52pm UTC](https://forum.developer.roku.com/t/hls-auto-switch/2662/7 "2012-09-30T21:52:28Z")

</div>

Thank you for quick reply!

I will add that code and will test again!

---

<div class="post-metadata">

**Author:** ![videodev](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@videodev](https://forum.developer.roku.com/u/videodev)\
**Post date:** [October 2, 2012, 12:39am UTC](https://forum.developer.roku.com/t/hls-auto-switch/2662/8 "2012-10-02T00:39:56Z")

</div>

> “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!

---

<div class="post-metadata">

**Author:** ![RokuJoel](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@RokuJoel](https://forum.developer.roku.com/u/RokuJoel)\
**Post date:** [October 2, 2012, 5:30pm UTC](https://forum.developer.roku.com/t/hls-auto-switch/2662/9 "2012-10-02T17:30:06Z")

</div>

If you set HDBranded=true the HD logo should show.

- Joel

---

<div class="post-metadata">

**Author:** ![danesor12](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@danesor12](https://forum.developer.roku.com/u/danesor12)\
**Post date:** [October 14, 2012, 4:21am UTC](https://forum.developer.roku.com/t/hls-auto-switch/2662/10 "2012-10-14T04:21:23Z")

</div>

Hi Joel,

Do you have a simple live streaming zip, an example which I can build on for live streaming studies? Similar to simple video player?  
Sometimes, solutions have a way of staring in my face and I am not able to see it.  
Appreciate all the help!

Thanks,

---

<div class="post-metadata">

**Author:** ![RokuJoel](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@RokuJoel](https://forum.developer.roku.com/u/RokuJoel)\
**Post date:** [October 16, 2012, 1:24am UTC](https://forum.developer.roku.com/t/hls-auto-switch/2662/11 "2012-10-16T01:24:30Z")

</div>

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

```auto

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

```

---

<div class="post-metadata">

**Author:** ![chubafelix](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@chubafelix](https://forum.developer.roku.com/u/chubafelix)\
**Post date:** [November 19, 2012, 3:23pm UTC](https://forum.developer.roku.com/t/hls-auto-switch/2662/12 "2012-11-19T15:23:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nyphur](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@Nyphur](https://forum.developer.roku.com/u/Nyphur)\
**Post date:** [April 13, 2013, 6:19am UTC](https://forum.developer.roku.com/t/hls-auto-switch/2662/13 "2013-04-13T06:19:33Z")

</div>

> “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 😞 Thanks in advance!

---

<div class="post-metadata">

**Author:** ![RokuMarkn](https://avatars.discourse-cdn.com/v4/letter/r/ac8455/32.png) [@RokuMarkn](https://forum.developer.roku.com/u/RokuMarkn)\
**Post date:** [April 13, 2013, 4:22pm UTC](https://forum.developer.roku.com/t/hls-auto-switch/2662/14 "2013-04-13T16:22:39Z")

</div>

Go to [sdkdocs.roku.com](http://sdkdocs.roku.com) and search for “SwitchingStrategy”.

–Mark

---

<div class="post-metadata">

**Author:** ![Nyphur](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@Nyphur](https://forum.developer.roku.com/u/Nyphur)\
**Post date:** [April 13, 2013, 5:19pm UTC](https://forum.developer.roku.com/t/hls-auto-switch/2662/15 "2013-04-13T17:19:33Z")

</div>

So I add a line

```auto
<SwitchingStrategy>full-adaption</SwitchingStrategy> in between the <media></media> tag?

```

---

<div class="post-metadata">

**Author:** ![bandal](https://avatars.discourse-cdn.com/v4/letter/b/c67d28/32.png) [@bandal](https://forum.developer.roku.com/u/bandal)\
**Post date:** [April 14, 2013, 5:10am UTC](https://forum.developer.roku.com/t/hls-auto-switch/2662/16 "2013-04-14T05:10:26Z")

</div>

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

```auto
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

```

---

<div class="post-metadata">

**Author:** ![Nyphur](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@Nyphur](https://forum.developer.roku.com/u/Nyphur)\
**Post date:** [April 17, 2013, 7:45am UTC](https://forum.developer.roku.com/t/hls-auto-switch/2662/17 "2013-04-17T07:45:46Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![RokuJoel](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@RokuJoel](https://forum.developer.roku.com/u/RokuJoel)\
**Post date:** [April 17, 2013, 7:02pm UTC](https://forum.developer.roku.com/t/hls-auto-switch/2662/18 "2013-04-17T19:02:16Z")

</div>

if you add a tag to your XML:

```auto
<SwitchingStrategh>full-adaptation</SwitchingStrategy>	

```

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

```auto
    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

---

<div class="post-metadata">

**Author:** ![gonzotek](https://sea3.discourse-cdn.com/roku/user_avatar/forum.developer.roku.com/gonzotek/32/93_2.png) [@gonzotek](https://forum.developer.roku.com/u/gonzotek)\
**Post date:** [April 17, 2013, 7:05pm UTC](https://forum.developer.roku.com/t/hls-auto-switch/2662/19 "2013-04-17T19:05:36Z")

</div>

> “RokuJoel” wrote:
> 
> ```auto
> Do watch out for typos though! :slightly_smiling_face:
> ```

---

<div class="post-metadata">

**Author:** ![Nyphur](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@Nyphur](https://forum.developer.roku.com/u/Nyphur)\
**Post date:** [April 20, 2013, 7:41am UTC](https://forum.developer.roku.com/t/hls-auto-switch/2662/20 "2013-04-20T07:41:08Z")

</div>

> “RokuJoel” wrote:  
> if you add a tag to your XML:
> 
> ```auto
> 
> ```

Can I follow that pattern for the other tags also?

I mean adding the code

```auto
<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](http://sdkdocs.roku.com/display/sdkdoc/Content+Meta-Data)

[Next page](https://forum.developer.roku.com/t/hls-auto-switch/2662.md?page=2)
