      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  * @param {object} file A {@link minplayer.file} object.
     44  * @return {number} The priority of this media player.
     45  */
     46 minplayer.players.flash.getPriority = function(file) {
     47   return 0;
     48 };
     49
     50 /**
     51  * @see minplayer.players.base#canPlay
     52  * @return {boolean} If this player can play this media type.
     53  */
     54 minplayer.players.flash.canPlay = function(file) {
     55   return false;
     56 };
     57
     58 /**
     59  * API to return the Flash player code provided params.
     60  *
     61  * @param {object} params The params used to populate the Flash code.
     62  * @return {object} A Flash DOM element.
     63  */
     64 minplayer.players.flash.prototype.getFlash = function(params) {
     65   // Get the protocol.
     66   var protocol = window.location.protocol;
     67   if (protocol.charAt(protocol.length - 1) == ':') {
     68     protocol = protocol.substring(0, protocol.length - 1);
     69   }
     70
     71   // Insert the swfobject javascript.
     72   var tag = document.createElement('script');
     73   var src = protocol;
     74   src += '://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js';
     75   tag.src = src;
     76   var firstScriptTag = document.getElementsByTagName('script')[0];
     77   firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
     78
     79   // Create the swfobject.
     80   setTimeout((function(player) {
     81     return function tryAgain() {
     82       if (typeof swfobject !== 'undefined') {
     83         swfobject.embedSWF(
     84           params.swf,
     85           params.id,
     86           params.width,
     87           params.height,
     88           '9.0.0',
     89           false,
     90           params.flashvars,
     91           {
     92             allowscriptaccess: 'always',
     93             allowfullscreen: 'true',
     94             wmode: params.wmode,
     95             quality: 'high'
     96           },
     97           {
     98             id: params.id,
     99             name: params.id,
    100             playerType: 'flash'
    101           },
    102           function(e) {
    103             player.player = e.ref;
    104           }
    105         );
    106       }
    107       else {
    108
    109         // Try again after 200 ms.
    110         setTimeout(tryAgain, 200);
    111       }
    112     };
    113   })(this), 200);
    114
    115   // Return the div tag...
    116   return '<div id="' + params.id + '"></div>';
    117 };
    118
    119 /**
    120  * @see minplayer.players.base#playerFound
    121  * @return {boolean} TRUE - if the player is in the DOM, FALSE otherwise.
    122  */
    123 minplayer.players.flash.prototype.playerFound = function() {
    124   return (this.display.find('object[playerType="flash"]').length > 0);
    125 };
    126