r104385 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104384‎ | r104385 | r104386 >
Date:01:31, 28 November 2011
Author:dale
Status:ok
Tags:
Comment:
* renamed postEmbedJS method to postEmbedActions ( no ambiguous "js" reference. )
other code review updates per: http://www.mediawiki.org/wiki/TimedMediaHandler/ReviewNotes#mw.EmbedPlayerVlc.js
* removed commented code
* localized player status updates
* code comments to make it more clear what the monitor section is doing
* included brackets
* updated $j ref to $ ref.
* prefixed all log messages with normal class name prefix
Modified paths:
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.EmbedPlayer.js (modified) (history)
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.EmbedPlayerKplayer.js (modified) (history)
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.EmbedPlayerNative.js (modified) (history)
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.EmbedPlayerVlc.js (modified) (history)

Diff [purge]

Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.EmbedPlayer.js
@@ -1991,7 +1991,7 @@
19921992 * Abstract method to be run post embedding the player Generally should be
19931993 * overwritten by the plug-in / player
19941994 */
1995 - postEmbedJS:function() {
 1995+ postEmbedActions:function() {
19961996 return ;
19971997 },
19981998
Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.EmbedPlayerVlc.js
@@ -2,8 +2,6 @@
33 * VLC embed based on: http://people.videolan.org/~damienf/plugin-0.8.6.html
44 * javascript api: http://www.videolan.org/doc/play-howto/en/ch04.html
55 * assume version > 0.8.5.1
6 -*
7 -* mark for deletion
86 */
97 ( function( mw, $ ) {
108
@@ -53,36 +51,22 @@
5452 '<embed pluginspage="http://www.videolan.org" type="application/x-vlc-plugin" ' +
5553 'progid="VideoLAN.VLCPlugin.2" name="' + this.pid + '" ' +
5654 'height="' + this.getHeight() + '" width="' + this.getWidth() + '" ' +
57 - // set the style too 'just to be sure'
 55+ // Set the style for IE layout issues )
5856 'style="width:' + this.getWidth() + 'px;height:' + this.getHeight() + 'px;" ' +
5957 '>' +
6058 '</object>'
6159 )
62 - /*
63 - $( this ).html(
64 - '<embed type="application/x-vlc-plugin" pluginspage="http://www.videolan.org" version="VideoLAN.VLCPlugin.2" '+
65 - 'width="' + this.width +'" ' +
66 - 'height="' + this.height + '" ' +
67 - 'id="' + this.pid + '"> ' +
68 - '</embed>'
69 - );*/
70 -
71 -
72 - // give VLC 150ms to initialize before we start playback
73 - // @@todo should be able to do this as an ready event
74 - this.waitForVlcCount = 0;
75 - setTimeout( function() {
76 - _this.postEmbedJS();
77 - }, 150 );
 60+ // Call postEmbedActions directly ( postEmbedJs will wait for player ready )
 61+ _this.postEmbedActions();
7862 },
7963
8064 /**
8165 * Javascript to run post vlc embedding
8266 * Inserts the requested src to the embed instance
8367 */
84 - postEmbedJS: function() {
 68+ postEmbedActions: function() {
8569 var _this = this;
86 - // load a pointer to the vlc into the object (this.playerElement)
 70+ // Load a pointer to the vlc into the object (this.playerElement)
8771 this.getPlayerElement();
8872 if ( this.playerElement && this.playerElement.playlist) {
8973 // manipulate the dom object to make sure vlc has the correct size:
@@ -93,27 +77,26 @@
9478 // VLC likes absolute urls:
9579 var src = mw.absoluteUrl( this.getSrc() ) ;
9680
97 - // @@todo if client supports seeking no need to send seek_offset to URI
98 - mw.log( 'vlc play::' + src );
 81+ mw.log( "EmbedPlayerVlc:: postEmbedActions play src:" + src );
9982 var itemId = this.playerElement.playlist.add( src );
10083 if ( itemId != -1 ) {
10184 // Play
10285 this.playerElement.playlist.playItem( itemId );
10386 } else {
104 - mw.log( "error:cannot play at the moment !" );
 87+ mw.log( "Error:: EmbedPlayerVlc can not play" );
10588 }
10689 setTimeout( function() {
10790 _this.monitor();
10891 }, 100 );
10992 } else {
110 - mw.log( 'postEmbedJS: vlc not ready' );
 93+ mw.log( 'EmbedPlayerVlc:: postEmbedActions: vlc not ready' );
11194 this.waitForVlcCount++;
11295 if ( this.waitForVlcCount < 10 ) {
11396 setTimeout( function() {
114 - _this.postEmbedJS();
 97+ _this.postEmbedActions();
11598 }, 100 );
11699 } else {
117 - mw.log( 'vlc never ready' );
 100+ mw.log( 'EmbedPlayerVlc:: vlc never ready' );
118101 }
119102 }
120103 },
@@ -125,15 +108,16 @@
126109 */
127110 seek : function( percent ) {
128111 this.getPlayerElement();
 112+ // Use the parent (re) embed with new seek url method if urlTimeEncoding is supported.
129113 if ( this.supportsURLTimeEncoding() ) {
130114 this.parent_seek( percent );
131115 } else if ( this.playerElement ) {
132116 this.seeking = true;
133 - mw.log( "do vlc http seek to: " + percent )
 117+ mw.log( "EmbedPlayerVlc:: seek to: " + percent )
134118 if ( ( this.playerElement.input.state == 3 ) && ( this.playerElement.input.position != percent ) )
135119 {
136120 this.playerElement.input.position = percent;
137 - this.controlBuilder.setStatus( 'seeking...' );
 121+ this.controlBuilder.setStatus( gM('mwe-embedplayer-seeking') );
138122 }
139123 } else {
140124 this.doPlayThenSeek( percent );
@@ -147,23 +131,23 @@
148132 * @param {Float} percent Seek to this percent of the stream after playing
149133 */
150134 doPlayThenSeek:function( percent ) {
151 - mw.log( 'doPlayThenSeekHack' );
 135+ mw.log( 'EmbedPlayerVlc:: doPlayThenSeek' );
152136 var _this = this;
153137 this.play();
154 - var rfsCount = 0;
 138+ var seekCount = 0;
155139 var readyForSeek = function() {
156140 _this.getPlayerElement();
157141 var newState = _this.playerElement.input.state;
158 - // if playing we are ready to do the
 142+ // If playing we are ready to do the seek
159143 if ( newState == 3 ) {
160144 _this.seek( percent );
161145 } else {
162 - // try to get player for 10 seconds:
163 - if ( rfsCount < 200 ) {
 146+ // Try to get player for 10 seconds:
 147+ if ( seekCount < 200 ) {
164148 setTimeout( readyForSeek, 50 );
165149 rfsCount++;
166150 } else {
167 - mw.log( 'error:doPlayThenSeek failed' );
 151+ mw.log( 'Error: EmbedPlayerVlc doPlayThenSeek failed' );
168152 }
169153 }
170154 }
@@ -175,12 +159,11 @@
176160 */
177161 monitor: function() {
178162 this.getPlayerElement();
179 - if ( !this.playerElement )
 163+ if ( ! this.playerElement ){
180164 return ;
 165+ }
 166+ // Try to get relay vlc log messages to the console.
181167 try{
182 - //mw.log( 'state:' + this.playerElement.input.state);
183 - //mw.log('time: ' + this.playerElement.input.time);
184 - //mw.log('pos: ' + this.playerElement.input.position);
185168 if ( this.playerElement.log.messages.count > 0 ) {
186169 // there is one or more messages in the log
187170 var iter = this.playerElement.log.messages.iterator();
@@ -228,28 +211,28 @@
229212 this.onPlaying();
230213 }
231214 } catch( e ){
232 - mw.log("EmbedPlayerVlc::Monitor error");
 215+ mw.log("EmbedPlayerVlc:: Monitor error");
233216 }
234 - // update the status and check timmer via universal parent monitor
 217+ // Update the status and check timer via universal parent monitor
235218 this.parent_monitor();
236219 },
237220
238221 /**
239222 * Events:
240 - * NOTE : should be localized:
241223 */
242224 onOpen: function() {
243 - this.controlBuilder.setStatus( "Opening..." );
 225+ // Open is considered equivalent to other players buffer status:
 226+ this.controlBuilder.setStatus( gM('mwe-embedplayer-buffering') );
244227 },
245228 onBuffer: function() {
246 - this.controlBuilder.setStatus( "Buffering..." );
 229+ this.controlBuilder.setStatus( gM('mwe-embedplayer-buffering') );
247230 },
248231 onPlay: function() {
249232 this.onPlaying();
250233 },
251234 onPlaying: function() {
252235 this.seeking = false;
253 - // for now trust the duration from url over vlc input.length
 236+ // For now trust the duration from url over vlc input.length
254237 if ( !this.getDuration() && this.playerElement.input.length > 0 )
255238 {
256239 // mw.log('setting duration to ' + this.playerElement.input.length /1000);
@@ -266,19 +249,21 @@
267250 },
268251
269252 onPause: function() {
270 - this.parent_pause(); // update the inteface if paused via native control
 253+ // Update the interface if paused via native plugin
 254+ this.parent_pause();
271255 },
272256 onStop: function() {
273 - mw.log( 'vlc:onStop:' );
274 - if ( !this.seeking )
 257+ mw.log( 'EmbedPlayerVlc:: onStop' );
 258+ if ( !this.seeking ){
275259 this.onClipDone();
 260+ }
276261 },
277262
278263 /**
279264 * Handles play requests
280265 */
281 - play : function() {
282 - mw.log( 'f:vlcPlay' );
 266+ play: function() {
 267+ mw.log( 'EmbedPlayerVlc:: play' );
283268 // Update the interface
284269 this.parent_play();
285270 if ( this.getPlayerElement() ) {
@@ -304,13 +289,13 @@
305290 * Passes the Pause request to the plugin.
306291 * calls parent "pause" to update interface
307292 */
308 - pause : function() {
 293+ pause: function() {
309294 this.parent_pause(); // update the interface if paused via native control
310295 if ( this.getPlayerElement() ) {
311296 try{
312297 this.playerElement.playlist.togglePause();
313298 } catch( e ){
314 - mw.log("EmbedPlayerVlc could not pause video " + e);
 299+ mw.log("EmbedPlayerVlc:: Could not pause video " + e);
315300 }
316301 }
317302 },
@@ -321,16 +306,17 @@
322307 */
323308 toggleMute:function() {
324309 this.parent_toggleMute();
325 - if ( this.getPlayerElement() )
 310+ if ( this.getPlayerElement() ){
326311 this.playerElement.audio.toggleMute();
 312+ }
327313 },
328314
329315 /**
330316 * Update the player volume
331 - * @pram {Float} percent Percent of total volume
 317+ * @parm {Float} percent Percent of total volume
332318 */
333319 setPlayerElementVolume: function ( percent ) {
334 - if ( this.getPlayerElement() ) {
 320+ if ( this.getPlayerElement() && this.playerElement.audio ) {
335321 this.playerElement.audio.volume = percent * 100;
336322 }
337323 },
@@ -340,8 +326,9 @@
341327 * @return {Float} percent percent of total volume
342328 */
343329 getVolumen:function() {
344 - if ( this.getPlayerElement() )
 330+ if ( this.getPlayerElement() ){
345331 return this.playerElement.audio.volume / 100;
 332+ }
346333 },
347334
348335 /**
@@ -353,7 +340,7 @@
354341 try{
355342 this.playerElement.video.toggleFullscreen();
356343 } catch ( e ){
357 - mw.log("VlcEmbed:: toggle fullscreen : possible error: " + e);
 344+ mw.log("EmbedPlayerVlc:: toggle fullscreen : possible error: " + e);
358345 }
359346 }
360347 }
@@ -368,4 +355,4 @@
369356 }
370357 };
371358
372 -} )( window.mediaWiki, window.jQuery );
\ No newline at end of file
 359+} )( mediaWiki, jQuery );
Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.EmbedPlayerNative.js
@@ -90,14 +90,14 @@
9191 this.isFirstEmbedPlay = true;
9292
9393 if( vid && $( vid ).attr('src') == this.getSrc( this.currentTime ) ){
94 - _this.postEmbedJS();
 94+ _this.postEmbedActions();
9595 return ;
9696 }
9797 mw.log( "EmbedPlayerNative::embedPlayerHTML > play url:" + this.getSrc( this.currentTime ) + ' startOffset: ' + this.start_ntp + ' end: ' + this.end_ntp );
9898
9999 // Check if using native controls and already the "pid" is already in the DOM
100100 if( this.isPersistentNativePlayer() && vid ) {
101 - _this.postEmbedJS();
 101+ _this.postEmbedActions();
102102 return ;
103103 }
104104
@@ -109,8 +109,8 @@
110110 _this.getNativePlayerHtml()
111111 );
112112
113 - // Directly run postEmbedJS ( if playerElement is not available it will retry )
114 - _this.postEmbedJS();
 113+ // Directly run postEmbedActions ( if playerElement is not available it will retry )
 114+ _this.postEmbedActions();
115115 },
116116
117117 /**
@@ -160,9 +160,9 @@
161161 /**
162162 * Post element javascript, binds event listeners and starts monitor
163163 */
164 - postEmbedJS: function() {
 164+ postEmbedActions: function() {
165165 var _this = this;
166 - mw.log( "f:native:postEmbedJS:" );
 166+ mw.log( "f:native:postEmbedActions:" );
167167
168168 // Setup local pointer:
169169 var vid = this.getPlayerElement();
Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.EmbedPlayerKplayer.js
@@ -74,7 +74,7 @@
7575
7676 var orgJsReadyCallback = window.jsCallbackReady;
7777 window.jsCallbackReady = function( playerId ){
78 - _this.postEmbedJS();
 78+ _this.postEmbedActions();
7979 window.jsCallbackReady = orgJsReadyCallback;
8080 };
8181 // attributes and params:
@@ -93,10 +93,10 @@
9494
9595 // Flash player loses its bindings once it changes sizes::
9696 $(_this).bind('onOpenFullScreen', function() {
97 - _this.postEmbedJS();
 97+ _this.postEmbedActions();
9898 });
9999 $(_this).bind('onCloseFullScreen', function() {
100 - _this.postEmbedJS();
 100+ _this.postEmbedActions();
101101 });
102102 },
103103
@@ -106,7 +106,7 @@
107107 /**
108108 * javascript run post player embedding
109109 */
110 - postEmbedJS : function() {
 110+ postEmbedActions : function() {
111111 var _this = this;
112112 this.getPlayerElement();
113113
@@ -135,7 +135,7 @@
136136 return ;
137137 }
138138 setTimeout(function() {
139 - _this.postEmbedJS();
 139+ _this.postEmbedActions();
140140 }, 10);
141141 }
142142 },

Status & tagging log