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