How to: Redirect Android when using HLS video (Wowza or FMS)

 

 

 

How to redirect Android when using HLS or Apple HTTP Live Streaming

Example of using a simple javascript redirect to make sure Android works with HLS

 

I was doing some live HLS webcasting (live broadcast using HLS via FMS 4.5), I realized that many Android devices will playback m3u8 / HLS, but not if the HLS is streamed through an embedded HLS video player.

 

This is actually really good news about Android and HLS video

 

It means you do not have to setup 2 distinct live streams, one for iOS and one for everything else. You will have to redirect Android OS directly to the live stream and bypass any embedded HLS players though. Here is how to redirect an android, or any device, with HLS Live

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<script type="text/javascript">// we're playing on devices that orients themselves depending on where they are in space. let's try and control that a bit:
 
function hideAddressBar(){
if(document.documentElement.scrollHeight<window .outerHeight/window.devicePixelRatio)
document.documentElement.style.height=(window.outerHeight/window.devicePixelRatio)+'px';
setTimeout(window.scrollTo(1,1),1000); }
window.addEventListener("load",function(){hideAddressBar();}); window.addEventListener("orientationchange",function(){hideAddressBar();
});
</script><script type="text/javascript">// hello android device
var ua = navigator.userAgent.toLowerCase();  
var isAndroid = ua.indexOf("android") > -1; 
ua.indexOf("mobile"); if(isAndroid) {
window.location = 'http://streamer.gravlab.com/hls-live/livestream/test123.m3u8';
 }
// goodbye android device - redirected directly to the m3u8 / HLS live stream
</script>
</window></script>

 

0