Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple detection for fullscreen media playback on touch devices
;(function (TMW, $) {
var theUserAgent = navigator.userAgent.toLowerCase();
TMW.Supports = {
userAgent : navigator.userAgent.toLowerCase(),
platform : {
iOS : theUserAgent.indexOf('iphone') != -1 || theUserAgent.indexOf('ipad') != -1 || theUserAgent.indexOf('ipod') != -1,
android : theUserAgent.indexOf('android') != -1,
windowsPhone : theUserAgent.indexOf('windows phone') != -1
},
browser : {
chrome : (theUserAgent.indexOf('crios') != -1 || theUserAgent.indexOf('chrome') != -1),
safari : theUserAgent.indexOf('safari') != -1 && !(theUserAgent.indexOf('crios') != -1 || theUserAgent.indexOf('chrome') != -1),
ie : theUserAgent.indexOf('trident') != -1
},
device : {
ipad : theUserAgent.indexOf('ipad') != -1,
iphone : theUserAgent.indexOf('iphone') != -1,
ipodTouch : theUserAgent.indexOf('ipod') != -1
},
mediaPlaysFullscreen : function() {
if ( (TMW.Supports.device.iphone || TMW.Supports.device.ipodTouch) && (TMW.Supports.browser.safari || TMW.Supports.browser.chrome) ) {
// iPhone & iPod Touch with Mobile Safari || Chrome
return true;
} else if ( TMW.Supports.platform.windowsPhone && TMW.Supports.browser.ie ) {
// Windows Phone
return true;
} else {
// Does not play in fullscreen
return false;
}
}
};
})(window.TMW = window.TMW || {}, jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment