/* Copyright (c) 2015, L. Masipa. Antfarm All rights reserved. http://www.antfarm.co.za Version: 1.1 */ jwplayer.key = "SI4eGFKWY8MSQlmz81xIwBazSclxYjTGuggkSclWH4c="; var width, height, divtag, url, imagepath; var isMobile = { Android: function () { return navigator.userAgent.match(/Android/i); }, BlackBerry: function () { return navigator.userAgent.match(/BlackBerry/i); }, iOS: function () { return navigator.userAgent.match(/iPhone|iPad|iPod/i); }, Opera: function () { return navigator.userAgent.match(/Opera Mini/i); }, Windows: function () { return navigator.userAgent.match(/IEMobile/i) || navigator.userAgent.match(/WPDesktop/i); }, any: function () { return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows()); } }; navigator.sayswho = (function () { var N = navigator.appName, ua = navigator.userAgent, tem; // if IE11+ if (new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})").exec(ua) !== null) { var M = ["Internet Explorer"]; if (M && (tem = ua.match(/rv:([0-9]{1,}[\.0-9]{0,})/)) != null) M[2] = tem[1]; M = M ? [M[0], M[2]] : [N, navigator.appVersion, '-?']; return M; } var newM = ua.match(/(opera|chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i); if (newM && (tem = ua.match(/version\/([\.\d]+)/i)) != null) newM[2] = tem[1]; newM = newM ? [newM[1], newM[2]] : [N, navigator.appVersion, '-?']; return newM; })(); var isEmptyPreRoll = function (word) { var flag = false; if (word.match("{{preroll}}")) { flag = true; } return flag; } var primaryUrl, secondaryUrl, backupUrl, siteUrl, imagepath, width, height, divtag, preroll; var player = { primary: "http://capeant.antfarm.co.za:1935/capricornfm/capricornfm.stream/playlist.m3u8", secondary: "http://capeant.antfarm.co.za:8000/CapricornFM", backup: "rtmp://capeant.antfarm.co.za:1935/capricornfm/capricornfm.stream", rtsp: "rtsp://capeant.antfarm.co.za:1935/capricornfm/capricornfm.stream", preRoll: "{{preroll}}", retries: 0, initialize: function player(w, h, div, website, ipath, loader) { width = w; height = h; divtag = div; preroll = this.preRoll; // Defined Url Links primaryUrl = this.primary; secondaryUrl = this.secondary; backupUrl = this.backup; this.siteurl = website; this.imagepath = ipath; //document.getElementById(divtag).innerHTML = "{{failover}}"; if (loader) { this.radioPlayer(); } }, radioPlayer: function () { var playerInstance = jwplayer(divtag); var _playlist = []; if (!preroll.match("{preroll}")) { _playlist = [ { title: "pre roll", image: this.imagepath, file: preroll }, { title:"Live", image: this.imagepath, sources: [{ file: primaryUrl }, { file: secondaryUrl }, { file: backupUrl }] } ] } else { _playlist = [ { image: this.imagepath, sources: [{ file: primaryUrl }, { file: secondaryUrl }, { file: backupUrl }] } ]; } playerInstance.on('ready', function (e) { if(_playlist.length > 1) $('.jw-icon-playlist').css('display', 'none'); }); playerInstance.on("setupError", function (e) { var errorMessage = JSON.stringify(e); var ua = JSON.stringify(navigator.userAgent); if (isMobile.Android() || isMobile.BlackBerry()) { window.location.replace(player.rtsp); } }); playerInstance.on("error", function (e) { player.retries++; var mymessage = JSON.stringify(e); //alert(mymessage); if (player.retries < 2) { playerInstance.load({ file: player.retries === 1 ? secondaryUrl : backupUrl }); } if (e.message.match("No playable sources found") || e.message.match("Crossdomain loading denied") || e.message.match("File not found") || e.message.match("File could not be played") && (isMobile.Android() || isMobile.BlackBerry())) { window.location.replace(player.rtsp); } else { alert("cannot play stream"); } }); playerInstance.setup({ playlist: [ { image: this.imagepath, file: preroll }, { image: this.imagepath, sources: [{ file: primaryUrl }, { file: secondaryUrl }, { file: backupUrl }] } ], autostart: true, width: width, height: height, image: this.imagepath, //primary: "html5", //androidhls: true, hlshtml: true, abouttext: "About Us", aboutlink: this.siteurl }); } };