Created
November 24, 2010 13:35
-
-
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
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
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&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&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