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.minplayer = function(context, options, queue) { 17 18 // Derive from players flash. 19 minplayer.players.flash.call(this, context, options, queue); 20 }; 21 22 /** Derive from minplayer.players.flash. */ 23 minplayer.players.minplayer.prototype = new minplayer.players.flash(); 24 25 /** Reset the constructor. */ 26 minplayer.players.minplayer.prototype.constructor = minplayer.players.minplayer; 27 28 /** 29 * @see minplayer.plugin.construct 30 * @this minplayer.players.minplayer 31 */ 32 minplayer.players.minplayer.prototype.construct = function() { 33 34 // Call the players.flash constructor. 35 minplayer.players.flash.prototype.construct.call(this); 36 37 // Set the plugin name within the options. 38 this.options.pluginName = 'minplayer'; 39 }; 40 41 /** 42 * Called when the Flash player is ready. 43 * 44 * @param {string} id The media player ID. 45 */ 46 window.onFlashPlayerReady = function(id) { 47 var media = minplayer.get(id, 'media'); 48 var i = media.length; 49 while (i--) { 50 media[i].onReady(); 51 } 52 }; 53 54 /** 55 * Called when the Flash player updates. 56 * 57 * @param {string} id The media player ID. 58 * @param {string} eventType The event type that was triggered. 59 */ 60 window.onFlashPlayerUpdate = function(id, eventType) { 61 var media = minplayer.get(id, 'media'); 62 var i = media.length; 63 while (i--) { 64 media[i].onMediaUpdate(eventType); 65 } 66 }; 67 68 /** 69 * Used to debug from the Flash player to the browser console. 70 * 71 * @param {string} debug The debug string. 72 */ 73 window.onFlashPlayerDebug = function(debug) { 74 if (console && console.log) { 75 console.log(debug); 76 } 77 }; 78 79 /** 80 * @see minplayer.players.base#getPriority 81 * @param {object} file A {@link minplayer.file} object. 82 * @return {number} The priority of this media player. 83 */ 84 minplayer.players.minplayer.getPriority = function(file) { 85 // Force this player if the stream is set. 86 return file.stream ? 100 : 1; 87 }; 88 89 /** 90 * @see minplayer.players.base#canPlay 91 * @return {boolean} If this player can play this media type. 92 */ 93 minplayer.players.minplayer.canPlay = function(file) { 94 95 // If this has a stream, then the minplayer must play it. 96 if (file.stream) { 97 return true; 98 } 99 100 var isWEBM = jQuery.inArray(file.mimetype, [ 101 'video/x-webm', 102 'video/webm', 103 'application/octet-stream' 104 ]) >= 0; 105 return !isWEBM && (file.type == 'video' || file.type == 'audio'); 106 }; 107 108 /** 109 * @see minplayer.players.base#create 110 * @return {object} The media player entity. 111 */ 112 minplayer.players.minplayer.prototype.create = function() { 113 114 // Make sure we provide default options... 115 this.options = jQuery.extend({ 116 swfplayer: 'flash/minplayer.swf' 117 }, this.options); 118 119 minplayer.players.flash.prototype.create.call(this); 120 121 // The flash variables for this flash player. 122 var flashVars = { 123 'id': this.options.id, 124 'debug': this.options.debug, 125 'config': 'nocontrols', 126 'file': this.mediaFile.path, 127 'autostart': this.options.autoplay, 128 'autoload': this.options.autoload 129 }; 130 131 // Add a stream if one is provided. 132 if (this.mediaFile.stream) { 133 flashVars.stream = this.mediaFile.stream; 134 } 135 136 // Return a flash media player object. 137 return this.getFlash({ 138 swf: this.options.swfplayer, 139 id: this.options.id + '_player', 140 width: '100%', 141 height: '100%', 142 flashvars: flashVars, 143 wmode: this.options.wmode 144 }); 145 }; 146 147 /** 148 * Called when the Flash player has an update. 149 * 150 * @param {string} eventType The event that was triggered in the player. 151 */ 152 minplayer.players.minplayer.prototype.onMediaUpdate = function(eventType) { 153 switch (eventType) { 154 case 'mediaMeta': 155 this.onLoaded(); 156 break; 157 case 'mediaConnected': 158 this.onLoaded(); 159 break; 160 case 'mediaPlaying': 161 if (this.minplayerloaded) { 162 this.onPlaying(); 163 } 164 break; 165 case 'mediaPaused': 166 this.minplayerloaded = true; 167 this.onPaused(); 168 break; 169 case 'mediaComplete': 170 this.onComplete(); 171 break; 172 } 173 }; 174 175 /** 176 * Resets all variables. 177 */ 178 minplayer.players.minplayer.prototype.clear = function() { 179 minplayer.players.flash.prototype.clear.call(this); 180 this.minplayerloaded = this.options.autoplay || !this.options.autoload; 181 }; 182 183 /** 184 * @see minplayer.players.base#load 185 * @return {boolean} If this action was performed. 186 */ 187 minplayer.players.minplayer.prototype.load = function(file) { 188 if (minplayer.players.flash.prototype.load.call(this, file)) { 189 this.player.loadMedia(file.path, file.stream); 190 return true; 191 } 192 193 return false; 194 }; 195 196 /** 197 * @see minplayer.players.base#play 198 * @return {boolean} If this action was performed. 199 */ 200 minplayer.players.minplayer.prototype.play = function() { 201 if (minplayer.players.flash.prototype.play.call(this)) { 202 this.player.playMedia(); 203 return true; 204 } 205 206 return false; 207 }; 208 209 /** 210 * @see minplayer.players.base#pause 211 * @return {boolean} If this action was performed. 212 */ 213 minplayer.players.minplayer.prototype.pause = function() { 214 if (minplayer.players.flash.prototype.pause.call(this)) { 215 this.player.pauseMedia(); 216 return true; 217 } 218 219 return false; 220 }; 221 222 /** 223 * @see minplayer.players.base#stop 224 * @return {boolean} If this action was performed. 225 */ 226 minplayer.players.minplayer.prototype.stop = function() { 227 if (minplayer.players.flash.prototype.stop.call(this)) { 228 this.player.stopMedia(); 229 return true; 230 } 231 232 return false; 233 }; 234 235 /** 236 * @see minplayer.players.base#seek 237 * @return {boolean} If this action was performed. 238 */ 239 minplayer.players.minplayer.prototype.seek = function(pos) { 240 if (minplayer.players.flash.prototype.seek.call(this, pos)) { 241 this.player.seekMedia(pos); 242 return true; 243 } 244 245 return false; 246 }; 247 248 /** 249 * @see minplayer.players.base#setVolume 250 * @return {boolean} If this action was performed. 251 */ 252 minplayer.players.minplayer.prototype.setVolume = function(vol) { 253 if (minplayer.players.flash.prototype.setVolume.call(this, vol)) { 254 this.player.setVolume(vol); 255 return true; 256 } 257 258 return false; 259 }; 260 261 /** 262 * @see minplayer.players.base#getVolume 263 */ 264 minplayer.players.minplayer.prototype.getVolume = function(callback) { 265 if (this.isReady()) { 266 callback(this.player.getVolume()); 267 } 268 }; 269 270 /** 271 * @see minplayer.players.flash#getDuration 272 */ 273 minplayer.players.minplayer.prototype.getDuration = function(callback) { 274 if (this.isReady()) { 275 276 // Check to see if it is immediately available. 277 var duration = this.player.getDuration(); 278 if (duration) { 279 callback(duration); 280 } 281 else { 282 283 // If not, then poll every second for the duration. 284 this.poll('duration', (function(player) { 285 return function() { 286 duration = player.player.getDuration(); 287 if (duration) { 288 callback(duration); 289 } 290 return !duration; 291 }; 292 })(this), 1000); 293 } 294 } 295 }; 296 297 /** 298 * @see minplayer.players.base#getCurrentTime 299 */ 300 minplayer.players.minplayer.prototype.getCurrentTime = function(callback) { 301 if (this.isReady()) { 302 callback(this.player.getCurrentTime()); 303 } 304 }; 305 306 /** 307 * @see minplayer.players.base#getBytesLoaded 308 */ 309 minplayer.players.minplayer.prototype.getBytesLoaded = function(callback) { 310 if (this.isReady()) { 311 callback(this.player.getMediaBytesLoaded()); 312 } 313 }; 314 315 /** 316 * @see minplayer.players.base#getBytesTotal. 317 */ 318 minplayer.players.minplayer.prototype.getBytesTotal = function(callback) { 319 if (this.isReady()) { 320 callback(this.player.getMediaBytesTotal()); 321 } 322 }; 323