added HLS and ISM support to embed.js

This commit is contained in:
Niels Groot Obbink 2013-03-26 11:24:32 +01:00
parent 5e57ae56c4
commit 2e1296cf5e

View file

@ -1,7 +1,7 @@
function mistembed(streamname)
{
// return the current flash version
function flashVersion()
function flash_version()
{
var version = 0;
@ -10,7 +10,6 @@ function mistembed(streamname)
// 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
@ -20,10 +19,29 @@ function mistembed(streamname)
return parseInt(version, 10);
};
function html5_video_type(type)
{
var support = false;
try
{
var v = document.createElement('video');
if( v && v.canPlayType(type) != "" )
{
support = true;
}
}catch(e){}
return support;
}
// what does the browser support - used in hasSupport()
supports =
{
flashversion: flashVersion()
flashversion: flash_version(),
hls: html5_video_type('application/vnd.apple.mpegURL'),
ism: html5_video_type('application/vnd.ms-ss')
};
// return true if a type is supported
@ -35,12 +53,15 @@ function mistembed(streamname)
case 'rtmp': return supports.flashversion >= 10; break;
case 'flv': return supports.flashversion >= 7; break;
case 'hls': return supports.hls; break;
case 'ism': return supports.ism; break;
default: return false;
}
};
// build HTML for certain kinds of types
function buildPlayer(src, container, videowidth, videoheight)
function buildPlayer(src, container, videowidth, videoheight, vtype)
{
// used to recalculate the width/height
var ratio;
@ -65,14 +86,24 @@ function mistembed(streamname)
videoheight /= ratio;
}
// if the video type is 'live',
lappend = vtype == 'live' ? "&streamType=live" : "";
switch(src.type)
{
case 'f4v':
case 'rtmp':
case 'flv':
container.innerHTML = '<object width="' + videowidth + '" height="' + videoheight + '"><param name="movie" value="http://fpdownload.adobe.com/strobe/FlashMediaPlayback.swf"></param><param name="flashvars" value="src=' + encodeURI(src.url) + '&controlBarMode=floating&expandedBufferTime=4&minContinuousPlaybackTime=10"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://fpdownload.adobe.com/strobe/FlashMediaPlayback.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' + videowidth + '" height="' + videoheight + '" flashvars="src=' + encodeURI(src.url) + '&controlBarMode=floating&expandedBufferTime=4&minContinuousPlaybackTime=10"></embed></object>';
container.innerHTML = '<object width="' + videowidth + '" height="' + videoheight + '"><param name="movie" value="http://fpdownload.adobe.com/strobe/FlashMediaPlayback.swf"></param><param name="flashvars" value="src=' + encodeURI(src.url) + '&controlBarMode=floating&expandedBufferTime=4&minContinuousPlaybackTime=10' + lappend + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://fpdownload.adobe.com/strobe/FlashMediaPlayback.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' + videowidth + '" height="' + videoheight + '" flashvars="src=' + encodeURI(src.url) + '&controlBarMode=floating&expandedBufferTime=4&minContinuousPlaybackTime=10"></embed></object>';
break;
case 'hls':
case 'ism':
container.innerHTML = '<video width="' + videowidth + '" height="' + videoheight + '" src="' + encodeURI(src.url) + '" controls="controls" ><strong>No HTML5 video support</strong></video>';
break;
case 'fallback':
container.innerHTML = '<strong>No support for any player found</strong>';
break;
@ -105,7 +136,8 @@ function mistembed(streamname)
}else{
// no error, and sources found. Check the video types and output the best
// available video player.
var i, video
var i, video,
vtype = video.type ? video.type : 'unknown';
foundPlayer = false,
len = video.source.length;
@ -114,7 +146,7 @@ function mistembed(streamname)
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);
buildPlayer(video.source[i], container.parentNode, video.width, video.height, vtype);
// we've build a player, so we're done here
foundPlayer = true;