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     var canPlay = elem.canPlayType(playType);
  8     return ('no' !== canPlay) && ('' !== canPlay);
  9   }
 10   else {
 11     return false;
 12   }
 13 }
 14 
 15 /**
 16  * @constructor
 17  * @class This class is used to define the types of media that can be played
 18  * within the browser.
 19  * <p>
 20  * <strong>Usage:</strong>
 21  * <pre><code>
 22  *   var playTypes = new minplayer.compatibility();
 23  *
 24  *   if (playTypes.videoOGG) {
 25  *     console.log("This browser can play OGG video");
 26  *   }
 27  *
 28  *   if (playTypes.videoH264) {
 29  *     console.log("This browser can play H264 video");
 30  *   }
 31  *
 32  *   if (playTypes.videoWEBM) {
 33  *     console.log("This browser can play WebM video");
 34  *   }
 35  *
 36  *   if (playTypes.audioOGG) {
 37  *     console.log("This browser can play OGG audio");
 38  *   }
 39  *
 40  *   if (playTypes.audioMP3) {
 41  *     console.log("This browser can play MP3 audio");
 42  *   }
 43  *
 44  *   if (playTypes.audioMP4) {
 45  *     console.log("This browser can play MP4 audio");
 46  *   }
 47  * </code></pre>
 48  */
 49 minplayer.compatibility = function() {
 50   var elem = null;
 51 
 52   // Create a video element.
 53   elem = document.createElement('video');
 54 
 55   /** Can play OGG video */
 56   this.videoOGG = checkPlayType(elem, 'video/ogg');
 57 
 58   /** Can play H264 video */
 59   this.videoH264 = checkPlayType(elem, 'video/mp4');
 60 
 61   /** Can play WEBM video */
 62   this.videoWEBM = checkPlayType(elem, 'video/x-webm');
 63 
 64   // Create an audio element.
 65   elem = document.createElement('audio');
 66 
 67   /** Can play audio OGG */
 68   this.audioOGG = checkPlayType(elem, 'audio/ogg');
 69 
 70   /** Can play audio MP3 */
 71   this.audioMP3 = checkPlayType(elem, 'audio/mpeg');
 72 
 73   /** Can play audio MP4 */
 74   this.audioMP4 = checkPlayType(elem, 'audio/mp4');
 75 };
 76 
 77 if (!minplayer.playTypes) {
 78 
 79   /** The compatible playtypes for this browser. */
 80   minplayer.playTypes = new minplayer.compatibility();
 81 }
 82