function mistembed(streamname)
{
// 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;
try
{
var v = document.createElement('video');
if( v && v.canPlayType(type) != "" )
{
support = true; // true-ish, anyway
}
}catch(e){}
return support;
}
// 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 '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.scrollWidth, 10);
var containerheight = parseInt(container.scrollHeight, 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);
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" : "");
if( parseInt(maintype[1], 10) >= 10 )
{
flashplayer = 'http://fpdownload.adobe.com/strobe/FlashMediaPlayback_101.swf';
}else{
flashplayer = 'http://fpdownload.adobe.com/strobe/FlashMediaPlayback.swf';
}
container.innerHTML = '';
break;
case 'html5':
container.innerHTML = '';
break;
case 'silverlight':
container.innerHTML = '';
break;
case 'fallback':
container.innerHTML = 'No support for any player found';
break;
}
};
var video = mistvideo[streamname],
container = document.createElement('div'),
scripts = document.getElementsByTagName('script'),
me = scripts[scripts.length - 1];
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
container.innerHTML = ['Error: ', video.error, ''].join('');
}else if(video.source.length < 1)
{
// no stream sources
container.innerHTML = 'Error: no streams found';
}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(i = 0; i < len; i++)
{
//console.log("trying support for type " + video.source[i].type + " (" + parseType(video.source[i].type)[0] + " - " + parseType(video.source[i].type)[1] + ")");
if( hasSupport( video.source[i].type ) )
{
// we support this kind of video, so build it.
buildPlayer(video.source[i], container.parentNode, video.width, video.height, vtype);
// we've build a player, so we're done here
foundPlayer = true;
break; // break for() loop
}
}
if(!foundPlayer)
{
// of all the streams given, none was supported (eg. no flash and HTML5 video). Display error
buildPlayer({type: 'fallback'}, container.parentNode, video.width, video.height);
}
}
}