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 {function} ready Called when the player is ready. 15 */ 16 minplayer.players.flash = function(context, options, ready) { 17 18 // Derive from players base. 19 minplayer.players.base.call(this, context, options, ready); 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.players.base#getPriority 30 * @return {number} The priority of this media player. 31 */ 32 minplayer.players.flash.getPriority = function() { 33 return 0; 34 }; 35 36 /** 37 * @see minplayer.players.base#canPlay 38 * @return {boolean} If this player can play this media type. 39 */ 40 minplayer.players.flash.canPlay = function(file) { 41 return false; 42 }; 43 44 /** 45 * API to return the Flash player code provided params. 46 * 47 * @param {object} params The params used to populate the Flash code. 48 * @return {object} A Flash DOM element. 49 */ 50 minplayer.players.flash.getFlash = function(params) { 51 // Get the protocol. 52 var protocol = window.location.protocol; 53 var element = null; 54 var embed = null; 55 var paramKey = ''; 56 var flashParams = {}; 57 var param = null; 58 59 if (protocol.charAt(protocol.length - 1) === ':') { 60 protocol = protocol.substring(0, protocol.length - 1); 61 } 62 63 // Create an object element. 64 element = document.createElement('object'); 65 element.setAttribute('width', params.width); 66 element.setAttribute('height', params.height); 67 element.setAttribute('id', params.id); 68 element.setAttribute('name', params.id); 69 element.setAttribute('playerType', params.playerType); 70 71 // Setup a params array to make the param additions eaiser. 72 flashParams = { 73 'allowScriptAccess': 'always', 74 'allowfullscreen': 'true', 75 'movie': params.swf, 76 'wmode': params.wmode, 77 'quality': 'high', 78 'FlashVars': jQuery.param(params.flashvars) 79 }; 80 81 // Add the parameters. 82 for (paramKey in flashParams) { 83 if (flashParams.hasOwnProperty(paramKey)) { 84 param = document.createElement('param'); 85 param.setAttribute('name', paramKey); 86 param.setAttribute('value', flashParams[paramKey]); 87 element.appendChild(param); 88 } 89 } 90 91 // Add the embed element. 92 embed = document.createElement('embed'); 93 for (paramKey in flashParams) { 94 if (flashParams.hasOwnProperty(paramKey)) { 95 if (paramKey === 'movie') { 96 embed.setAttribute('src', flashParams[paramKey]); 97 } 98 else { 99 embed.setAttribute(paramKey, flashParams[paramKey]); 100 } 101 } 102 } 103 104 embed.setAttribute('width', params.width); 105 embed.setAttribute('height', params.height); 106 embed.setAttribute('id', params.id); 107 embed.setAttribute('name', params.id); 108 embed.setAttribute('swLiveConnect', 'true'); 109 embed.setAttribute('type', 'application/x-shockwave-flash'); 110 element.appendChild(embed); 111 return element; 112 }; 113 114 /** 115 * @see minplayer.players.base#playerFound 116 * @return {boolean} TRUE - if the player is in the DOM, FALSE otherwise. 117 */ 118 minplayer.players.flash.prototype.playerFound = function() { 119 return (this.display.find('object[playerType="flash"]').length > 0); 120 }; 121 122 /** 123 * @see minplayer.players.base#getMedia 124 * @return {object} The media player object. 125 */ 126 minplayer.players.flash.prototype.getMedia = function() { 127 // IE needs the object, everyone else just needs embed. 128 var object = jQuery.browser.msie ? 'object' : 'embed'; 129 return jQuery(object, this.display).eq(0)[0]; 130 }; 131