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 * 92 * @param {object} file A {@link minplayer.file} object. 93 * @return {boolean} If this player can play this media type. 94 */ 95 minplayer.players.minplayer.canPlay = function(file) { 96 97 // If this has a stream, then the minplayer must play it. 98 if (file.stream) { 99 return true; 100 } 101 102 var isWEBM = jQuery.inArray(file.mimetype, [ 103 'video/x-webm', 104 'video/webm', 105 'application/octet-stream' 106 ]) >= 0; 107 return !isWEBM && (file.type === 'video' || file.type === 'audio'); 108 }; 109 110 /** 111 * @see minplayer.players.base#create 112 * @return {object} The media player entity. 113 */ 114 minplayer.players.minplayer.prototype.createPlayer = function() { 115 116 // Make sure we provide default swfplayer... 117 if (!this.options.swfplayer) { 118 this.options.swfplayer = 'http://mediafront.org/assets/osmplayer/minplayer'; 119 this.options.swfplayer += '/flash/minplayer.swf'; 120 } 121 122 minplayer.players.flash.prototype.createPlayer.call(this); 123 124 // The flash variables for this flash player. 125 var flashVars = { 126 'id': this.options.id, 127 'debug': this.options.debug, 128 'config': 'nocontrols', 129 'file': this.mediaFile.path, 130 'autostart': this.options.autoplay, 131 'autoload': this.options.autoload 132 }; 133 134 // Add a stream if one is provided. 135 if (this.mediaFile.stream) { 136 flashVars.stream = this.mediaFile.stream; 137 } 138 139 // Return a flash media player object. 140 return this.getFlash({ 141 swf: this.options.swfplayer, 142 id: this.options.id + '_player', 143 width: '100%', 144 height: '100%', 145 flashvars: flashVars, 146 wmode: this.options.wmode 147 }); 148 }; 149 150 /** 151 * Called when the Flash player has an update. 152 * 153 * @param {string} eventType The event that was triggered in the player. 154 */ 155 minplayer.players.minplayer.prototype.onMediaUpdate = function(eventType) { 156 switch (eventType) { 157 case 'mediaMeta': 158 this.onLoaded(); 159 break; 160 case 'mediaConnected': 161 this.onLoaded(); 162 this.onPaused(); 163 break; 164 case 'mediaPlaying': 165 this.onPlaying(); 166 break; 167 case 'mediaPaused': 168 this.onPaused(); 169 break; 170 case 'mediaComplete': 171 this.onComplete(); 172 break; 173 } 174 }; 175 176 /** 177 * Load the media in the minplayer. 178 * 179 * @param file 180 * @param callback 181 * @private 182 */ 183 minplayer.players.minplayer.prototype.load = function(file, callback) { 184 minplayer.players.flash.prototype.load.call(this, file, function() { 185 if (this.loaded) { 186 this.stop(function() { 187 this.player.loadMedia(file.path, file.stream); 188 if (callback) { 189 callback.call(this); 190 } 191 }); 192 } 193 else { 194 this.player.loadMedia(file.path, file.stream); 195 if (callback) { 196 callback.call(this); 197 } 198 } 199 }); 200 }; 201 202 /** 203 * @see minplayer.players.base#play 204 */ 205 minplayer.players.minplayer.prototype.play = function(callback) { 206 minplayer.players.flash.prototype.play.call(this, function() { 207 this.player.playMedia(); 208 if (callback) { 209 callback.call(this); 210 } 211 }); 212 }; 213 214 /** 215 * @see minplayer.players.base#pause 216 */ 217 minplayer.players.minplayer.prototype.pause = function(callback) { 218 minplayer.players.flash.prototype.pause.call(this, function() { 219 this.player.pauseMedia(); 220 if (callback) { 221 callback.call(this); 222 } 223 }); 224 }; 225 226 /** 227 * @see minplayer.players.base#stop 228 */ 229 minplayer.players.minplayer.prototype.stop = function(callback) { 230 minplayer.players.flash.prototype.stop.call(this, function() { 231 this.player.stopMedia(); 232 if (callback) { 233 callback.call(this); 234 } 235 }); 236 }; 237 238 /** 239 * @see minplayer.players.base#_seek 240 */ 241 minplayer.players.minplayer.prototype._seek = function(pos) { 242 this.player.seekMedia(pos); 243 }; 244 245 /** 246 * @see minplayer.players.base#setVolume 247 */ 248 minplayer.players.minplayer.prototype.setVolume = function(vol, callback) { 249 minplayer.players.flash.prototype.setVolume.call(this, vol, function() { 250 this.player.setVolume(vol); 251 if (callback) { 252 callback.call(this); 253 } 254 }); 255 }; 256 257 /** 258 * @see minplayer.players.base#getVolume 259 */ 260 minplayer.players.minplayer.prototype._getVolume = function(callback) { 261 callback(this.player.getVolume()); 262 }; 263 264 /** 265 * @see minplayer.players.flash#getDuration 266 */ 267 minplayer.players.minplayer.prototype._getDuration = function(callback) { 268 var self = this, duration = 0; 269 var tryDuration = function() { 270 duration = self.player.getDuration(); 271 if (duration) { 272 callback(duration); 273 } 274 else { 275 setTimeout(tryDuration, 1000); 276 } 277 }; 278 tryDuration(); 279 }; 280 281 /** 282 * @see minplayer.players.base#getCurrentTime 283 */ 284 minplayer.players.minplayer.prototype._getCurrentTime = function(callback) { 285 callback(this.player.getCurrentTime()); 286 }; 287 288 /** 289 * @see minplayer.players.base#_getBytesLoaded 290 */ 291 minplayer.players.minplayer.prototype._getBytesLoaded = function(callback) { 292 callback(this.player.getMediaBytesLoaded()); 293 }; 294 295 /** 296 * @see minplayer.players.base#_getBytesTotal. 297 */ 298 minplayer.players.minplayer.prototype._getBytesTotal = function(callback) { 299 callback(this.player.getMediaBytesTotal()); 300 }; 301