Skip to content

Instantly share code, notes, and snippets.

@benbarnett
Created November 24, 2010 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save benbarnett/713656 to your computer and use it in GitHub Desktop.
Save benbarnett/713656 to your computer and use it in GitHub Desktop.
Detect Flash support and revert to standard YouTube embed code to enable HTML5 player
if (swfobject.hasFlashPlayerVersion("8.0.0")) {
// insert the chromeless player with custom controls and skinning
alert('you have flash, so getting the chromeless/skinned player');
// Lets Flash from another domain call JavaScript
var params = { allowScriptAccess: "always" };
// The element id of the Flash embed
var atts = { id: "ytPlayer" };
// All of the magic handled by SWFObject (http://code.google.com/p/swfobject/)
swfobject.embedSWF("http://www.youtube.com/apiplayer?" +
"&enablejsapi=1&playerapiid=player1",
"videoDiv", "640", "385", "8", null, null, params, atts);
}
else {
// insert the standard embed, standard controls but html5 supported
alert('no flash, using html5 player if possible');
var videoDiv = document.getElementById('videoDiv');
videoDiv.innerHTML = '<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/YJp7tqRyJAI?fs=1&amp;hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/YJp7tqRyJAI?fs=1&amp;hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment