1 /** The minplayer namespace. */
  2 var minplayer = minplayer || {};
  3 
  4 /** All the media player implementations */
  5 minplayer.players = minplayer.players || {};
  6 
  7 /**
  8  * @constructor
  9  * @extends minplayer.display
 10  * @class The Flash media player class to control the flash fallback.
 11  *
 12  * @param {object} context The jQuery context.
 13  * @param {object} options This components options.
 14  * @param {object} queue The event queue to pass events around.
 15  */
 16 minplayer.players.flash = function(context, options, queue) {
 17 
 18   // Derive from players base.
 19   minplayer.players.base.call(this, context, options, queue);
 20 };
 21 
 22 /** Derive from minplayer.players.base. */
 23 minplayer.players.flash.prototype = new minplayer.players.base();
 24 
 25 /** Reset the constructor. */
 26 minplayer.players.flash.prototype.constructor = minplayer.players.flash;
 27 
 28 /**
 29  * @see minplayer.plugin.construct
 30  * @this minplayer.players.flash
 31  */
 32 minplayer.players.flash.prototype.construct = function() {
 33 
 34   // Call the players.base constructor.
 35   minplayer.players.base.prototype.construct.call(this);
 36 
 37   // Set the plugin name within the options.
 38   this.options.pluginName = 'flash';
 39 };
 40 
 41 /**
 42  * @see minplayer.players.base#getPriority
 43  * @return {number} The priority of this media player.
 44  */
 45 minplayer.players.flash.getPriority = function() {
 46   return 0;
 47 };
 48 
 49 /**
 50  * @see minplayer.players.base#canPlay
 51  * @return {boolean} If this player can play this media type.
 52  */
 53 minplayer.players.flash.canPlay = function(file) {
 54   return false;
 55 };
 56 
 57 /**
 58  * API to return the Flash player code provided params.
 59  *
 60  * @param {object} params The params used to populate the Flash code.
 61  * @return {object} A Flash DOM element.
 62  */
 63 minplayer.players.flash.prototype.getFlash = function(params) {
 64   // Get the protocol.
 65   var protocol = window.location.protocol;
 66   if (protocol.charAt(protocol.length - 1) == ':') {
 67     protocol = protocol.substring(0, protocol.length - 1);
 68   }
 69 
 70   // Insert the swfobject javascript.
 71   var tag = document.createElement('script');
 72   var src = protocol;
 73   src += '://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js';
 74   tag.src = src;
 75   var firstScriptTag = document.getElementsByTagName('script')[0];
 76   firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
 77 
 78   // Create the swfobject.
 79   setTimeout((function(player) {
 80     return function tryAgain() {
 81       if (typeof swfobject !== 'undefined') {
 82         swfobject.embedSWF(
 83           params.swf,
 84           params.id,
 85           params.width,
 86           params.height,
 87           '9.0.0',
 88           false,
 89           params.flashvars,
 90           {
 91             allowscriptaccess: 'always',
 92             allowfullscreen: 'true',
 93             wmode: params.wmode,
 94             quality: 'high'
 95           },
 96           {
 97             id: params.id,
 98             name: params.id,
 99             playerType: 'flash'
100           },
101           function(e) {
102             player.player = e.ref;
103           }
104         );
105       }
106       else {
107 
108         // Try again after 200 ms.
109         setTimeout(tryAgain, 200);
110       }
111     };
112   })(this), 200);
113 
114   // Return the div tag...
115   return '<div id="' + params.id + '"></div>';
116 };
117 
118 /**
119  * @see minplayer.players.base#playerFound
120  * @return {boolean} TRUE - if the player is in the DOM, FALSE otherwise.
121  */
122 minplayer.players.flash.prototype.playerFound = function() {
123   return (this.display.find('object[playerType="flash"]').length > 0);
124 };
125