Skip to content

Instantly share code, notes, and snippets.

@derick-montague
Created August 9, 2012 17:18
Show Gist options
  • Save derick-montague/3306076 to your computer and use it in GitHub Desktop.
Save derick-montague/3306076 to your computer and use it in GitHub Desktop.
jPlayer - detect browser and set fallback when html 5 video not supported
<script>
/****************************************************************************************************
Checking for old IE and Firefox versions and defaulting to flash with html 5 fallback
Not serving .ogg file so Firefox requires Flash
Flash does not like dimensions set to auto, so set these to 100% when using flash for playback
****************************************************************************************************/
$(document).ready(function(){
var ua = $.browser;
var uaVersion = ua.version.slice(0,3);
var videoWidth = "auto";
var videoHeight = "auto";
var fallbackSetting = "html, flash";
var isOldIE = ua.msie && uaVersion < 9;
var isFirefox = ua.mozilla;
if (isOldIE || isFirefox)
{
videoWidth = "100%";
videoHeight = "100%";
}
if (isFirefox) {
fallbackSetting = "flash, html";
}
$("#jquery_jplayer_1").jPlayer({
ready: function () {
$(this).jPlayer("setMedia", {
m4v: "/path-to-my.mp4",
poster: "/path-to-my-poster.jpg"
});
},
swfPath: "/behavior",
supplied: "m4v",
size: {
width: videoWidth,
height: videoHeight,
cssClass: "jp-video-base"
},
sizeFull: {
cssClass: "jp-video-full"
},
solution: fallbackSetting
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment