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 */ 15 minplayer.players.minplayer = function(context, options) { 16 17 // Derive from players flash. 18 minplayer.players.flash.call(this, context, options); 19 }; 20 21 /** Derive from minplayer.players.flash. */ 22 minplayer.players.minplayer.prototype = new minplayer.players.flash(); 23 24 /** Reset the constructor. */ 25 minplayer.players.minplayer.prototype.constructor = minplayer.players.minplayer; 26 27 /** 28 * Called when the Flash player is ready. 29 * 30 * @param {string} id The media player ID. 31 */ 32 window.onFlashPlayerReady = function(id) { 33 var media = minplayer.get(id, 'media'); 34 if (media) { 35 media.onReady(); 36 } 37 }; 38 39 /** 40 * Called when the Flash player updates. 41 * 42 * @param {string} id The media player ID. 43 * @param {string} eventType The event type that was triggered. 44 */ 45 window.onFlashPlayerUpdate = function(id, eventType) { 46 var media = minplayer.get(id, 'media'); 47 if (media) { 48 media.onMediaUpdate(eventType); 49 } 50 }; 51 52 /** 53 * Used to debug from the Flash player to the browser console. 54 * 55 * @param {string} debug The debug string. 56 */ 57 window.onFlashPlayerDebug = function(debug) { 58 minplayer.console.log(debug); 59 }; 60 61 /** 62 * @see minplayer.players.base#getPriority 63 * @return {number} The priority of this media player. 64 */ 65 minplayer.players.minplayer.getPriority = function() { 66 return 1; 67 }; 68 69 /** 70 * @see minplayer.players.base#canPlay 71 * @return {boolean} If this player can play this media type. 72 */ 73 minplayer.players.minplayer.canPlay = function(file) { 74 switch (file.mimetype) { 75 case 'video/mp4': 76 case 'video/x-webm': 77 case 'video/quicktime': 78 case 'video/3gpp2': 79 case 'video/3gpp': 80 case 'application/x-shockwave-flash': 81 case 'audio/mpeg': 82 case 'audio/mp4': 83 case 'audio/aac': 84 case 'audio/vnd.wave': 85 case 'audio/x-ms-wma': 86 return true; 87 88 default: 89 return false; 90 } 91 }; 92 93 /** 94 * @see minplayer.players.base#create 95 * @return {object} The media player entity. 96 */ 97 minplayer.players.minplayer.prototype.create = function() { 98 minplayer.players.flash.prototype.create.call(this); 99 100 // The flash variables for this flash player. 101 var flashVars = { 102 'id': this.options.id, 103 'debug': this.options.debug, 104 'config': 'nocontrols', 105 'file': this.mediaFile.path, 106 'autostart': this.options.autoplay 107 }; 108 109 // Return a flash media player object. 110 return minplayer.players.flash.getFlash({ 111 swf: this.options.swfplayer, 112 id: this.options.id + '_player', 113 width: this.options.width, 114 height: '100%', 115 flashvars: flashVars, 116 wmode: this.options.wmode 117 }); 118 }; 119 120 /** 121 * Called when the Flash player has an update. 122 * 123 * @param {string} eventType The event that was triggered in the player. 124 */ 125 minplayer.players.minplayer.prototype.onMediaUpdate = function(eventType) { 126 switch (eventType) { 127 case 'mediaMeta': 128 this.onLoaded(); 129 break; 130 case 'mediaPlaying': 131 this.onPlaying(); 132 break; 133 case 'mediaPaused': 134 this.onPaused(); 135 break; 136 case 'mediaComplete': 137 this.onComplete(); 138 break; 139 } 140 }; 141 142 /** 143 * @see minplayer.players.base#load 144 */ 145 minplayer.players.minplayer.prototype.load = function(file) { 146 minplayer.players.flash.prototype.load.call(this, file); 147 if (file && this.isReady()) { 148 this.player.loadMedia(file.path, file.stream); 149 } 150 }; 151 152 /** 153 * @see minplayer.players.base#play 154 */ 155 minplayer.players.minplayer.prototype.play = function() { 156 minplayer.players.flash.prototype.play.call(this); 157 if (this.isReady()) { 158 this.player.playMedia(); 159 } 160 }; 161 162 /** 163 * @see minplayer.players.base#pause 164 */ 165 minplayer.players.minplayer.prototype.pause = function() { 166 minplayer.players.flash.prototype.pause.call(this); 167 if (this.isReady()) { 168 this.player.pauseMedia(); 169 } 170 }; 171 172 /** 173 * @see minplayer.players.base#stop 174 */ 175 minplayer.players.minplayer.prototype.stop = function() { 176 minplayer.players.flash.prototype.stop.call(this); 177 if (this.isReady()) { 178 this.player.stopMedia(); 179 } 180 }; 181 182 /** 183 * @see minplayer.players.base#seek 184 */ 185 minplayer.players.minplayer.prototype.seek = function(pos) { 186 minplayer.players.flash.prototype.seek.call(this, pos); 187 if (this.isReady()) { 188 this.player.seekMedia(pos); 189 } 190 }; 191 192 /** 193 * @see minplayer.players.base#setVolume 194 */ 195 minplayer.players.minplayer.prototype.setVolume = function(vol) { 196 minplayer.players.flash.prototype.setVolume.call(this, vol); 197 if (this.isReady()) { 198 this.player.setVolume(vol); 199 } 200 }; 201 202 /** 203 * @see minplayer.players.base#getVolume 204 */ 205 minplayer.players.minplayer.prototype.getVolume = function(callback) { 206 if (this.isReady()) { 207 callback(this.player.getVolume()); 208 } 209 }; 210 211 /** 212 * @see minplayer.players.flash#getDuration 213 */ 214 minplayer.players.minplayer.prototype.getDuration = function(callback) { 215 if (this.isReady()) { 216 217 // Check to see if it is immediately available. 218 var duration = this.player.getDuration(); 219 if (duration) { 220 callback(duration); 221 } 222 else { 223 224 // If not, then check every half second... 225 var _this = this; 226 setTimeout(function check() { 227 duration = _this.player.getDuration(); 228 if (duration) { 229 callback(duration); 230 } 231 else { 232 setTimeout(check, 500); 233 } 234 }, 500); 235 } 236 } 237 }; 238 239 /** 240 * @see minplayer.players.base#getCurrentTime 241 */ 242 minplayer.players.minplayer.prototype.getCurrentTime = function(callback) { 243 if (this.isReady()) { 244 callback(this.player.getCurrentTime()); 245 } 246 }; 247 248 /** 249 * @see minplayer.players.base#getBytesLoaded 250 */ 251 minplayer.players.minplayer.prototype.getBytesLoaded = function(callback) { 252 if (this.isReady()) { 253 callback(this.player.getMediaBytesLoaded()); 254 } 255 }; 256 257 /** 258 * @see minplayer.players.base#getBytesTotal. 259 */ 260 minplayer.players.minplayer.prototype.getBytesTotal = function(callback) { 261 if (this.isReady()) { 262 callback(this.player.getMediaBytesTotal()); 263 } 264 }; 265