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 {function} ready Called when the player is ready.
 15  */
 16 minplayer.players.minplayer = function(context, options, ready) {
 17 
 18   // Derive from players flash.
 19   minplayer.players.flash.call(this, context, options, ready);
 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   if (minplayer.player[id]) {
 35     minplayer.player[id].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   if (minplayer.player[id]) {
 47     minplayer.player[id].media.onMediaUpdate(eventType);
 48   }
 49 };
 50 
 51 var debugConsole = console || {log: function(data) {}};
 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   debugConsole.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-webm':
 78     case 'video/quicktime':
 79     case 'video/3gpp2':
 80     case 'video/3gpp':
 81     case 'application/x-shockwave-flash':
 82     case 'audio/mpeg':
 83     case 'audio/mp4':
 84     case 'audio/aac':
 85     case 'audio/vnd.wave':
 86     case 'audio/x-ms-wma':
 87       return true;
 88 
 89     default:
 90       return false;
 91   }
 92 };
 93 
 94 /**
 95  * @see minplayer.players.base#create
 96  * @return {object} The media player entity.
 97  */
 98 minplayer.players.minplayer.prototype.create = function() {
 99   minplayer.players.flash.prototype.create.call(this);
100 
101   // The flash variables for this flash player.
102   var flashVars = {
103     'id': this.options.id,
104     'debug': this.options.debug,
105     'config': 'nocontrols',
106     'file': this.mediaFile.path,
107     'autostart': this.options.autoplay
108   };
109 
110   // Return a flash media player object.
111   return minplayer.players.flash.getFlash({
112     swf: this.options.swfplayer,
113     id: this.options.id + '_player',
114     playerType: 'flash',
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.media.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.media.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.media.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.media.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.media.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.media.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.media.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     callback(this.media.getDuration());
219   }
220 };
221 
222 /**
223  * @see minplayer.players.base#getCurrentTime
224  */
225 minplayer.players.minplayer.prototype.getCurrentTime = function(callback) {
226   if (this.isReady()) {
227     callback(this.media.getCurrentTime());
228   }
229 };
230 
231 /**
232  * @see minplayer.players.base#getBytesLoaded
233  */
234 minplayer.players.minplayer.prototype.getBytesLoaded = function(callback) {
235   if (this.isReady()) {
236     callback(this.media.getMediaBytesLoaded());
237   }
238 };
239 
240 /**
241  * @see minplayer.players.base#getBytesTotal.
242  */
243 minplayer.players.minplayer.prototype.getBytesTotal = function(callback) {
244   if (this.isReady()) {
245     callback(this.media.getMediaBytesTotal());
246   }
247 };
248