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/webm':
 78     case 'application/octet-stream':
 79     case 'video/quicktime':
 80     case 'video/3gpp2':
 81     case 'video/3gpp':
 82     case 'application/x-shockwave-flash':
 83     case 'audio/mpeg':
 84     case 'audio/mp4':
 85     case 'audio/aac':
 86     case 'audio/vnd.wave':
 87     case 'audio/x-ms-wma':
 88       return true;
 89 
 90     default:
 91       return false;
 92   }
 93 };
 94 
 95 /**
 96  * @see minplayer.players.base#create
 97  * @return {object} The media player entity.
 98  */
 99 minplayer.players.minplayer.prototype.create = function() {
100   minplayer.players.flash.prototype.create.call(this);
101 
102   // The flash variables for this flash player.
103   var flashVars = {
104     'id': this.options.id,
105     'debug': this.options.debug,
106     'config': 'nocontrols',
107     'file': this.mediaFile.path,
108     'autostart': this.options.autoplay
109   };
110 
111   // Return a flash media player object.
112   return minplayer.players.flash.getFlash({
113     swf: this.options.swfplayer,
114     id: this.options.id + '_player',
115     width: this.options.width,
116     height: '100%',
117     flashvars: flashVars,
118     wmode: this.options.wmode
119   });
120 };
121 
122 /**
123  * Called when the Flash player has an update.
124  *
125  * @param {string} eventType The event that was triggered in the player.
126  */
127 minplayer.players.minplayer.prototype.onMediaUpdate = function(eventType) {
128   switch (eventType) {
129     case 'mediaMeta':
130       this.onLoaded();
131       break;
132     case 'mediaPlaying':
133       this.onPlaying();
134       break;
135     case 'mediaPaused':
136       this.onPaused();
137       break;
138     case 'mediaComplete':
139       this.onComplete();
140       break;
141   }
142 };
143 
144 /**
145  * @see minplayer.players.base#load
146  */
147 minplayer.players.minplayer.prototype.load = function(file) {
148   minplayer.players.flash.prototype.load.call(this, file);
149   if (file && this.isReady()) {
150     this.player.loadMedia(file.path, file.stream);
151   }
152 };
153 
154 /**
155  * @see minplayer.players.base#play
156  */
157 minplayer.players.minplayer.prototype.play = function() {
158   minplayer.players.flash.prototype.play.call(this);
159   if (this.isReady()) {
160     this.player.playMedia();
161   }
162 };
163 
164 /**
165  * @see minplayer.players.base#pause
166  */
167 minplayer.players.minplayer.prototype.pause = function() {
168   minplayer.players.flash.prototype.pause.call(this);
169   if (this.isReady()) {
170     this.player.pauseMedia();
171   }
172 };
173 
174 /**
175  * @see minplayer.players.base#stop
176  */
177 minplayer.players.minplayer.prototype.stop = function() {
178   minplayer.players.flash.prototype.stop.call(this);
179   if (this.isReady()) {
180     this.player.stopMedia();
181   }
182 };
183 
184 /**
185  * @see minplayer.players.base#seek
186  */
187 minplayer.players.minplayer.prototype.seek = function(pos) {
188   minplayer.players.flash.prototype.seek.call(this, pos);
189   if (this.isReady()) {
190     this.player.seekMedia(pos);
191   }
192 };
193 
194 /**
195  * @see minplayer.players.base#setVolume
196  */
197 minplayer.players.minplayer.prototype.setVolume = function(vol) {
198   minplayer.players.flash.prototype.setVolume.call(this, vol);
199   if (this.isReady()) {
200     this.player.setVolume(vol);
201   }
202 };
203 
204 /**
205  * @see minplayer.players.base#getVolume
206  */
207 minplayer.players.minplayer.prototype.getVolume = function(callback) {
208   if (this.isReady()) {
209     callback(this.player.getVolume());
210   }
211 };
212 
213 /**
214  * @see minplayer.players.flash#getDuration
215  */
216 minplayer.players.minplayer.prototype.getDuration = function(callback) {
217   if (this.isReady()) {
218 
219     // Check to see if it is immediately available.
220     var duration = this.player.getDuration();
221     if (duration) {
222       callback(duration);
223     }
224     else {
225 
226       // If not, then check every half second...
227       var _this = this;
228       setTimeout(function check() {
229         duration = _this.player.getDuration();
230         if (duration) {
231           callback(duration);
232         }
233         else {
234           setTimeout(check, 500);
235         }
236       }, 500);
237     }
238   }
239 };
240 
241 /**
242  * @see minplayer.players.base#getCurrentTime
243  */
244 minplayer.players.minplayer.prototype.getCurrentTime = function(callback) {
245   if (this.isReady()) {
246     callback(this.player.getCurrentTime());
247   }
248 };
249 
250 /**
251  * @see minplayer.players.base#getBytesLoaded
252  */
253 minplayer.players.minplayer.prototype.getBytesLoaded = function(callback) {
254   if (this.isReady()) {
255     callback(this.player.getMediaBytesLoaded());
256   }
257 };
258 
259 /**
260  * @see minplayer.players.base#getBytesTotal.
261  */
262 minplayer.players.minplayer.prototype.getBytesTotal = function(callback) {
263   if (this.isReady()) {
264     callback(this.player.getMediaBytesTotal());
265   }
266 };
267