function mistembed(streamname) { //find the current script var me; if (('currentScript' in document) && (document.currentScript)) { me = document.currentScript; //not supported in old browsers :( } else { var scripts = document.getElementsByTagName('script'); me = scripts[scripts.length - 1]; //not correct if the script is inserted dynamically, but this is how it used to be } // return the current flash version function flash_version() { var version = 0; try { // check in the mimeTypes version = navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin.description.replace(/([^0-9\.])/g, '').split('.')[0]; } catch(e){} try { // for our special friend IE version = new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable("$version").replace(/([^0-9\,])/g, '').split(',')[0]; } catch(e){} return parseInt(version, 10); }; // return true if silverlight is installed function silverlight_installed() { var plugin; try { // check in the mimeTypes plugin = navigator.plugins["Silverlight Plug-In"]; return !!plugin; } catch(e){} try { // for our special friend IE plugin = new ActiveXObject('AgControl.AgControl'); return true; } catch(e){} return false; }; // return true if the browser thinks it can play the mimetype function html5_video_type(type) { var support = false; if (type == 'video/mp4') { if ((navigator.userAgent.indexOf('MSIE') > -1) && (parseInt(navigator.userAgent.split('MSIE')[1]) <= 9)) { //IE <= 9 doesn't support MP4, Firefox seems to correctly see it now. return false; } if (navigator.userAgent.indexOf('Firefox') > -1) { //firefox claims to support MP4 but doesn't when: // - under win xp // - the stream is live if (video.type == 'live') { return false; } //find "Windows NT X;" in user userAgent //sorry, I don't like regexes.. I avoid them when I can :$ var s = navigator.userAgent.split('Windows NT '); if (s.length > 1) { s = s[1].split(';'); s = s[0]; if (Number(s) <= 5.1) { return false; } } } } try { var v = document.createElement('video'); if( v && v.canPlayType(type) != "" ) { support = true; // true-ish, anyway } } catch(e){} return support; } //return true if rtsp is supported function rtsp_support() { var plugin; try { // check in the mimeTypes plugin = navigator.mimeTypes["application/x-google-vlc-plugin"]; return !!plugin; } catch(e){} try { // for our special friend IE plugin = new ActiveXObject('VideoLAN.Vlcplugin.1'); return true; } catch(e){} return false; } // parse a "type" string from the controller. Format: // xxx/# (e.g. flash/3) or xxx/xxx/xxx (e.g. html5/application/ogg) function parseType(type) { var split = type.split('/'); if( split.length > 2 ) { split[1] += '/' + split[2]; } return split; } // return true if a type is supported function hasSupport(type) { var typemime = parseType(type); switch(typemime[0]) { case 'flash': return flash_version() >= parseInt(typemime[1], 10); break; case 'html5': return html5_video_type(typemime[1]); break; case 'rtsp': return rtsp_support(); break; case 'silverlight': return silverlight_installed(); break; default: return false; break; } } // build HTML for certain kinds of types function buildPlayer(src, container, videowidth, videoheight, vtype) { // used to recalculate the width/height var ratio; // get the container's width/height var containerwidth = parseInt(container.clientWidth, 10); var containerheight = parseInt(container.clientHeight, 10); if(videowidth > containerwidth && containerwidth > 0) { ratio = videowidth / containerwidth; videowidth /= ratio; videoheight /= ratio; } if(videoheight > containerheight && containerheight > 0) { ratio = videoheight / containerheight; videowidth /= ratio; videoheight /= ratio; } var maintype = parseType(src.type); mistvideo[streamname].embedded = src; switch(maintype[0]) { case 'flash': // maintype[1] is already checked (i.e. user has version > maintype[1]) var flashplayer, url = encodeURIComponent(src.url) + '&controlBarMode=floating&initialBufferTime=0.5&expandedBufferTime=5&minContinuousPlaybackTime=3' + (vtype == 'live' ? "&streamType=live" : "") + (autoplay ? '&autoPlay=true' : ''); /* if( parseInt(maintype[1], 10) >= 10 ) { flashplayer = 'http://fpdownload.adobe.com/strobe/FlashMediaPlayback_101.swf'; } else { flashplayer = 'http://fpdownload.adobe.com/strobe/FlashMediaPlayback.swf'; } */ flashplayer = src.player_url; container.innerHTML += '' + '' + '' + '' + '' + '' + (autoplay ? '' : '') + '' + ''; break; case 'html5': container.innerHTML += ''; break; case 'rtsp': /*container.innerHTML += ''+ ''+ ''+ ''+ ''+ ''+ ''+ 'Something went wrong.'+ ''; //realplayer, doesnt work */ container.innerHTML += ''+ ''+ ''+ ''; //vlc, seems to work, sort of. it's trying anyway break; case 'silverlight': container.innerHTML += ''+ ''+ ''+ ''+ ''+ ''+ ''+ '\' />'+ ' Get Microsoft Silverlight'+ ''; break; default: container.innerHTML += 'Missing embed code for output type "'+src.type+'"'; video.error = 'Missing embed code for output type "'+src.type; } } var video = mistvideo[streamname], container = document.createElement('div'), forceType = false, forceSupportCheck = false, autoplay = true, urlappend = false; if (me.parentNode.hasAttribute('data-forcetype')) { forceType = me.parentNode.getAttribute('data-forcetype'); } if (me.parentNode.hasAttribute('data-forcesupportcheck')) { forceSupportCheck = true; } if (me.parentNode.hasAttribute('data-noautoplay')) { autoplay = false; } if (me.parentNode.hasAttribute('data-urlappend')) { urlappend = me.parentNode.getAttribute('data-urlappend'); } if (video.width == 0) { video.width = 250; } if (video.height == 0) { video.height = 250; } // create the container me.parentNode.insertBefore(container, me); // set the class to 'mistvideo' container.setAttribute('class', 'mistvideo'); // remove script tag me.parentNode.removeChild(me); if(video.error) { // there was an error; display it if (video.on_error){ container.innerHTML = video.on_error; }else{ container.innerHTML = ['Error: ', video.error, ''].join(''); } } else if ((typeof video.source == 'undefined') || (video.source.length < 1)) { // no stream sources if (video.on_error){ container.innerHTML = video.on_error; }else{ container.innerHTML = 'Error: no active source or compatible protocols for this stream'; } } else { // no error, and sources found. Check the video types and output the best // available video player. var i, vtype = (video.type ? video.type : 'unknown'), foundPlayer = false, len = video.source.length; for (var i in video.source) { var support = hasSupport(video.source[i].type); video.source[i].browser_support = support; if ((support) || (forceType)) { if ((!forceType) || ((forceType) && (video.source[i].type.indexOf(forceType) >= 0))) { if (foundPlayer === false) { foundPlayer = i; if (!forceSupportCheck) { break; } } } } } if (foundPlayer === false) { // of all the streams given, none was supported (eg. no flash and HTML5 video). Display error container.innerHTML = 'No support for any player found'; } else { // we support this kind of video, so build it. var source = video.source[foundPlayer]; if (urlappend) { source.url += urlappend; source.relurl += urlappend; } else if (me.src.indexOf('?') != -1) { var params = me.src.split('?'); params.shift(); params.join('?'); source.url += '?'+params; source.relurl += '?'+params; } buildPlayer(source, container, video.width, video.height, vtype); } } return (mistvideo[streamname].embedded ? mistvideo[streamname].embedded.type : false); //keep empty line at end of file }