r103563 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103562‎ | r103563 | r103564 >
Date:02:50, 18 November 2011
Author:dale
Status:ok
Tags:
Comment:
cleaned up setCurrentTime method
adjusted time outs for seek operations
removed delay for postEmbed js ( no longer needed )
Modified paths:
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.EmbedPlayerNative.js (modified) (history)

Diff [purge]

Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.EmbedPlayerNative.js
@@ -86,29 +86,25 @@
8787 */
8888 embedPlayerHTML : function () {
8989 var _this = this;
90 -
91 - // Reset some play state flags:
92 - _this.bufferStartFlag = false;
93 - _this.bufferEndFlag = false;
 90+ var vid = _this.getPlayerElement();
 91+ this.isFirstEmbedPlay = true;
9492
95 - mw.log( "EmbedPlayerNative:: play url:" + this.getSrc( this.currentTime ) + ' startOffset: ' + this.start_ntp + ' end: ' + this.end_ntp );
96 -
 93+ if( vid && $( vid ).attr('src') == this.getSrc( this.currentTime ) ){
 94+ _this.postEmbedJS();
 95+ return ;
 96+ }
 97+ mw.log( "EmbedPlayerNative::embedPlayerHTML > play url:" + this.getSrc( this.currentTime ) + ' startOffset: ' + this.start_ntp + ' end: ' + this.end_ntp );
 98+
9799 // Check if using native controls and already the "pid" is already in the DOM
98 - if( ( this.useNativePlayerControls()
99 - ||
100 - this.isPersistentNativePlayer()
101 - )
102 - && $( '#' + this.pid ).length
103 - && typeof $( '#' + this.pid ).get(0).play != 'undefined' ) {
104 -
105 - // Update the player source:
106 - $( '#' + this.pid ).attr( 'src', this.getSrc( this.currentTime ) );
107 - $( '#' + this.pid ).get(0).load();
108 -
 100+ if( this.isPersistentNativePlayer() && vid ) {
109101 _this.postEmbedJS();
110102 return ;
111103 }
112 -
 104+
 105+ // Reset some play state flags:
 106+ _this.bufferStartFlag = false;
 107+ _this.bufferEndFlag = false;
 108+
113109 $( this ).html(
114110 _this.getNativePlayerHtml()
115111 );
@@ -128,8 +124,12 @@
129125 playerAttribtues = {};
130126 }
131127 // Update required attributes
132 - if( !playerAttribtues['id'] ) playerAttribtues['id'] = this.pid;
133 - if( !playerAttribtues['src'] ) playerAttribtues['src'] = this.getSrc( this.currentTime);
 128+ if( !playerAttribtues['id'] ){
 129+ playerAttribtues['id'] = this.pid;
 130+ }
 131+ if( !playerAttribtues['src'] ){
 132+ playerAttribtues['src'] = this.getSrc( this.currentTime);
 133+ }
134134
135135 // If autoplay pass along to attribute ( needed for iPad / iPod no js autoplay support
136136 if( this.autoplay ) {
@@ -148,7 +148,7 @@
149149 playerAttribtues['loop'] = 'true';
150150 }
151151
152 - var tagName = ( this.isAudio() ) ? 'audio' : 'video';
 152+ var tagName = this.isAudio() ? 'audio' : 'video';
153153
154154 return $( '<' + tagName + ' />' )
155155 // Add the special nativeEmbedPlayer to avoid any rewrites of of this video tag.
@@ -177,10 +177,7 @@
178178 // Issue play request
179179 vid.play();
180180 }
181 -
182 - setTimeout( function() {
183 - _this.monitor();
184 - }, 100 );
 181+ _this.monitor();
185182 },
186183
187184 /**
@@ -232,7 +229,7 @@
233230 * @param {Float} percentage
234231 */
235232 seek: function( percentage ) {
236 - mw.log( 'Native::seek p: ' + percentage + ' : ' + this.supportsURLTimeEncoding() + ' dur: ' + this.getDuration() + ' sts:' + this.seek_time_sec );
 233+ mw.log( 'EmbedPlayerNative::seek p: ' + percentage + ' : ' + this.supportsURLTimeEncoding() + ' dur: ' + this.getDuration() + ' sts:' + this.seek_time_sec );
237234 this.seeking = true;
238235
239236 // Run the onSeeking interface update
@@ -242,7 +239,7 @@
243240 if ( this.supportsURLTimeEncoding() ) {
244241 // Make sure we could not do a local seek instead:
245242 if ( percentage < this.bufferedPercent && this.playerElement.duration && !this.didSeekJump ) {
246 - mw.log( "do local seek " + percentage + ' is already buffered < ' + this.bufferedPercent );
 243+ mw.log( "EmbedPlayerNative:: do local seek " + percentage + ' is already buffered < ' + this.bufferedPercent );
247244 this.doNativeSeek( percentage );
248245 } else {
249246 // We support URLTimeEncoding call parent seek:
@@ -264,7 +261,7 @@
265262 */
266263 doNativeSeek: function( percentage ) {
267264 var _this = this;
268 - mw.log( 'native::doNativeSeek::' + percentage );
 265+ mw.log( 'EmbedPlayerNative::doNativeSeek::' + percentage );
269266 this.seeking = true;
270267 this.seek_time_sec = 0;
271268 this.setCurrentTime( ( percentage * this.duration ) , function(){
@@ -280,7 +277,7 @@
281278 * Percentage of the stream to seek to between 0 and 1
282279 */
283280 doPlayThenSeek: function( percentage ) {
284 - mw.log( 'native::doPlayThenSeek::' );
 281+ mw.log( 'EmbedPlayerNative::doPlayThenSeek::' );
285282 var _this = this;
286283 this.play();
287284 var retryCount = 0;
@@ -292,11 +289,11 @@
293290 } else {
294291 // Try to get player for 40 seconds:
295292 // (it would be nice if the onmetadata type callbacks where fired consistently)
296 - if ( retryCount < 800 ) {
297 - setTimeout( readyForSeek, 50 );
 293+ if ( retryCount < 400 ) {
 294+ setTimeout( readyForSeek, 100 );
298295 retryCount++;
299296 } else {
300 - mw.log( 'error:doPlayThenSeek failed' );
 297+ mw.log( 'Error:doPlayThenSeek failed' );
301298 }
302299 }
303300 }
@@ -313,40 +310,48 @@
314311 */
315312 setCurrentTime: function( time , callback, callbackCount ) {
316313 var _this = this;
317 - if( !callbackCount )
 314+ if( !callbackCount ){
318315 callbackCount = 0;
319 - this.getPlayerElement();
320 - if( _this.playerElement.readyState >= 1 ){
321 - if( _this.playerElement.currentTime == time ){
322 - if( callback ){
323 - callback();
324 - }
325 - return;
326 - }
327 - var once = function( event ) {
328 - if( callback ){
329 - callback();
330 - }
331 - _this.playerElement.removeEventListener( 'seeked', once, false );
332 - };
333 - // Assume we will get to add the Listener before the seek is done
334 - _this.playerElement.addEventListener( 'seeked', once, false );
335 - try {
336 - _this.playerElement.currentTime = time;
337 - } catch (e) {
338 - mw.log("Could not seek to this point. Unbuffered point.");
339 - callback();
340 - return;
341 - }
342 - } else {
343 - if( callbackCount >= 300 ){
 316+ }
 317+ var vid = this.getPlayerElement();
 318+
 319+ // Check if player is ready for seek:
 320+ if( vid.readyState < 1 ){
 321+ if( callbackCount >= 400 ){
344322 mw.log("Error with seek request, media never in ready state");
345323 return ;
346324 }
347325 setTimeout( function(){
348326 _this.setCurrentTime( time, callback , callbackCount++);
349 - }, 10 );
 327+ }, 100 );
 328+ return ;
350329 }
 330+ // Check if currentTime is already set to the seek target:
 331+ if( vid.currentTime == time ){
 332+ if( callback ){
 333+ callback();
 334+ }
 335+ return;
 336+ }
 337+
 338+ // Setup a local function callback for successful seek
 339+ var once = function( event ) {
 340+ // Remove the listner:
 341+ vid.removeEventListener( 'seeked', once, false );
 342+ if( callback ){
 343+ callback();
 344+ }
 345+ };
 346+ // Assume we will get to add the Listener before the seek is done
 347+ vid.addEventListener( 'seeked', once, false );
 348+ // Try to update the playerElement time:
 349+ try {
 350+ vid.currentTime = time;
 351+ } catch (e) {
 352+ mw.log("Error Could not set video tag time");
 353+ callback();
 354+ return;
 355+ }
351356 },
352357
353358 /**

Status & tagging log