HLS video javascript redirect for mobile video {ios / iphone / ipad / Blackberry / Android} or rollover to protected flash / rtmp

 

Instead of trying to force players to work well across platforms, occasionally we’ll find it better to redirect certain devices away from the embedded player directly to the video file itself and have the native player take it. Here’s a customizable code snippet that does that.

 

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>start here: detect device</title>   
<script type="text/javascript">
    if (navigator.userAgent.indexOf('iPhone') != -1) {
        document.location = "http://gravitylab.gravlab.net/iOS/Book-People/Book-People_43198769.m3u8";
    }
    if (navigator.userAgent.indexOf('iPad') != -1) {
        document.location = "http://gravitylab.gravlab.net/iOS/Book-People/Book-People_43198769.m3u8";
    }
	if (navigator.userAgent.indexOf('iPod') != -1) {
        document.location = "http://gravitylab.gravlab.net/iOS/Book-People/Book-People_43198769.m3u8";
    }
    if (navigator.userAgent.indexOf('Blackberry') != -1) {
        document.location = "http://gravitylab.gravlab.net/blackberry/Book-People.mp4";
    }
    if (navigator.userAgent.indexOf('Android') != -1) {
        document.location = "html5.html";
    }
</script>
</head>
<!-- OK, so now whatever is left isn't any of those devices above,
 send them to rtmp:// flash video to protect from casual downloading -->
<body>
<script language="JavaScript">self.location="protected_flash.html";</script>
</body>

 

Here are Gravitylab’s other video redirect scripts, some are for HLS video, some for HTML5 that we’ve used over the years to get mobile video to the right screen.

9 karma points