Created
February 9, 2011 12:06
-
-
Save Nutrox/818368 to your computer and use it in GitHub Desktop.
JavaScript - Media Playback Detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this is part of my core javascript code, it detects flash and MP4 media playback capabilities | |
window.core = new function() { | |
var document = window.document; | |
var navigator = window.navigator; | |
var flashVersion = null; | |
var flashAvailable = false; | |
var audioAvailable = false; // MP4 | |
var videoAvailable = false; // MP4 | |
// new closure used to isolate variables | |
new function() { | |
// partial HTML5 element rendering fix for MSIE < 9 | |
if( /MSIE [0-8]\./.test(navigator.userAgent) ) { | |
var a = [ | |
"article", | |
"aside", | |
"footer", | |
"header", | |
"section" | |
]; | |
while( a.length ) { | |
document.createElement( a.pop() ); | |
} | |
} | |
var o; | |
var v; | |
var x = /([0-9]+).([0-9]+).[a-z]?([0-9]+)/; | |
try { | |
o = navigator.plugins["Shockwave Flash"]; | |
v = o.description.match( x ); | |
} | |
catch( error ) { | |
try { | |
o = new ActiveXObject( "ShockwaveFlash.ShockwaveFlash" ); | |
v = o.GetVariable( "$version" ).match( x ); | |
} | |
catch( error ) {} | |
} | |
if( v ) { | |
flashVersion = [ v[1]-0, v[2]-0, v[3]-0 ]; | |
flashAvailable = true; | |
if( flashVersion[0] > 9 || flashVersion[0] == 9 && flashVersion[2] >= 152 ) { | |
audioAvailable = true; | |
videoAvailable = true; | |
return; // HTML5 media elements not required | |
} | |
} | |
o = document.createElement( "audio" ); | |
if( o.canPlayType ) { | |
audioAvailable = o.canPlayType( "audio/mp4; codecs=\"mp4a\"" ) == "probably"; | |
} | |
o = document.createElement( "video" ); | |
if( o.canPlayType ) { | |
videoAvailable = o.canPlayType( "video/mp4; codecs=\"avc1,mp4a\"" ) == "probably"; | |
} | |
} | |
// | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment