1 /** The minplayer namespace. */ 2 var minplayer = minplayer || {}; 3 4 // Private function to check a single element's play type. 5 function checkPlayType(elem, playType) { 6 if ((typeof elem.canPlayType) === 'function') { 7 if (typeof playType === 'object') { 8 var i = playType.length; 9 var mimetype = ''; 10 while (i--) { 11 mimetype = checkPlayType(elem, playType[i]); 12 if (!!mimetype) { 13 break; 14 } 15 } 16 return mimetype; 17 } 18 else { 19 var canPlay = elem.canPlayType(playType); 20 if (('no' !== canPlay) && ('' !== canPlay)) { 21 return playType; 22 } 23 } 24 } 25 return ''; 26 } 27 28 /** 29 * @constructor 30 * @class This class is used to define the types of media that can be played 31 * within the browser. 32 * <p> 33 * <strong>Usage:</strong> 34 * <pre><code> 35 * var playTypes = new minplayer.compatibility(); 36 * 37 * if (playTypes.videoOGG) { 38 * console.log("This browser can play OGG video"); 39 * } 40 * 41 * if (playTypes.videoH264) { 42 * console.log("This browser can play H264 video"); 43 * } 44 * 45 * if (playTypes.videoWEBM) { 46 * console.log("This browser can play WebM video"); 47 * } 48 * 49 * if (playTypes.audioOGG) { 50 * console.log("This browser can play OGG audio"); 51 * } 52 * 53 * if (playTypes.audioMP3) { 54 * console.log("This browser can play MP3 audio"); 55 * } 56 * 57 * if (playTypes.audioMP4) { 58 * console.log("This browser can play MP4 audio"); 59 * } 60 * </code></pre> 61 */ 62 minplayer.compatibility = function() { 63 var elem = null; 64 65 // Create a video element. 66 elem = document.createElement('video'); 67 68 /** Can play OGG video */ 69 this.videoOGG = checkPlayType(elem, 'video/ogg'); 70 71 /** Can play H264 video */ 72 this.videoH264 = checkPlayType(elem, [ 73 'video/mp4', 74 'video/h264' 75 ]); 76 77 /** Can play WEBM video */ 78 this.videoWEBM = checkPlayType(elem, [ 79 'video/x-webm', 80 'video/webm', 81 'application/octet-stream' 82 ]); 83 84 // Create an audio element. 85 elem = document.createElement('audio'); 86 87 /** Can play audio OGG */ 88 this.audioOGG = checkPlayType(elem, 'audio/ogg'); 89 90 /** Can play audio MP3 */ 91 this.audioMP3 = checkPlayType(elem, 'audio/mpeg'); 92 93 /** Can play audio MP4 */ 94 this.audioMP4 = checkPlayType(elem, 'audio/mp4'); 95 }; 96 97 if (!minplayer.playTypes) { 98 99 /** The compatible playtypes for this browser. */ 100 minplayer.playTypes = new minplayer.compatibility(); 101 102 /** See if we are an android device. */ 103 minplayer.isAndroid = (/android/gi).test(navigator.appVersion); 104 105 /** See if we are an iOS device. */ 106 minplayer.isIDevice = (/iphone|ipad/gi).test(navigator.appVersion); 107 108 /** See if we are a playbook device. */ 109 minplayer.isPlaybook = (/playbook/gi).test(navigator.appVersion); 110 111 /** See if we are a touchpad device. */ 112 minplayer.isTouchPad = (/hp-tablet/gi).test(navigator.appVersion); 113 114 /** Determine if we have a touchscreen. */ 115 minplayer.hasTouch = 'ontouchstart' in window && !minplayer.isTouchPad; 116 } 117