Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.EmbedPlayerNative.js |
— | — | @@ -86,29 +86,25 @@ |
87 | 87 | */ |
88 | 88 | embedPlayerHTML : function () { |
89 | 89 | 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; |
94 | 92 | |
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 | + |
97 | 99 | // 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 ) { |
109 | 101 | _this.postEmbedJS(); |
110 | 102 | return ; |
111 | 103 | } |
112 | | - |
| 104 | + |
| 105 | + // Reset some play state flags: |
| 106 | + _this.bufferStartFlag = false; |
| 107 | + _this.bufferEndFlag = false; |
| 108 | + |
113 | 109 | $( this ).html( |
114 | 110 | _this.getNativePlayerHtml() |
115 | 111 | ); |
— | — | @@ -128,8 +124,12 @@ |
129 | 125 | playerAttribtues = {}; |
130 | 126 | } |
131 | 127 | // 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 | + } |
134 | 134 | |
135 | 135 | // If autoplay pass along to attribute ( needed for iPad / iPod no js autoplay support |
136 | 136 | if( this.autoplay ) { |
— | — | @@ -148,7 +148,7 @@ |
149 | 149 | playerAttribtues['loop'] = 'true'; |
150 | 150 | } |
151 | 151 | |
152 | | - var tagName = ( this.isAudio() ) ? 'audio' : 'video'; |
| 152 | + var tagName = this.isAudio() ? 'audio' : 'video'; |
153 | 153 | |
154 | 154 | return $( '<' + tagName + ' />' ) |
155 | 155 | // Add the special nativeEmbedPlayer to avoid any rewrites of of this video tag. |
— | — | @@ -177,10 +177,7 @@ |
178 | 178 | // Issue play request |
179 | 179 | vid.play(); |
180 | 180 | } |
181 | | - |
182 | | - setTimeout( function() { |
183 | | - _this.monitor(); |
184 | | - }, 100 ); |
| 181 | + _this.monitor(); |
185 | 182 | }, |
186 | 183 | |
187 | 184 | /** |
— | — | @@ -232,7 +229,7 @@ |
233 | 230 | * @param {Float} percentage |
234 | 231 | */ |
235 | 232 | 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 ); |
237 | 234 | this.seeking = true; |
238 | 235 | |
239 | 236 | // Run the onSeeking interface update |
— | — | @@ -242,7 +239,7 @@ |
243 | 240 | if ( this.supportsURLTimeEncoding() ) { |
244 | 241 | // Make sure we could not do a local seek instead: |
245 | 242 | 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 ); |
247 | 244 | this.doNativeSeek( percentage ); |
248 | 245 | } else { |
249 | 246 | // We support URLTimeEncoding call parent seek: |
— | — | @@ -264,7 +261,7 @@ |
265 | 262 | */ |
266 | 263 | doNativeSeek: function( percentage ) { |
267 | 264 | var _this = this; |
268 | | - mw.log( 'native::doNativeSeek::' + percentage ); |
| 265 | + mw.log( 'EmbedPlayerNative::doNativeSeek::' + percentage ); |
269 | 266 | this.seeking = true; |
270 | 267 | this.seek_time_sec = 0; |
271 | 268 | this.setCurrentTime( ( percentage * this.duration ) , function(){ |
— | — | @@ -280,7 +277,7 @@ |
281 | 278 | * Percentage of the stream to seek to between 0 and 1 |
282 | 279 | */ |
283 | 280 | doPlayThenSeek: function( percentage ) { |
284 | | - mw.log( 'native::doPlayThenSeek::' ); |
| 281 | + mw.log( 'EmbedPlayerNative::doPlayThenSeek::' ); |
285 | 282 | var _this = this; |
286 | 283 | this.play(); |
287 | 284 | var retryCount = 0; |
— | — | @@ -292,11 +289,11 @@ |
293 | 290 | } else { |
294 | 291 | // Try to get player for 40 seconds: |
295 | 292 | // (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 ); |
298 | 295 | retryCount++; |
299 | 296 | } else { |
300 | | - mw.log( 'error:doPlayThenSeek failed' ); |
| 297 | + mw.log( 'Error:doPlayThenSeek failed' ); |
301 | 298 | } |
302 | 299 | } |
303 | 300 | } |
— | — | @@ -313,40 +310,48 @@ |
314 | 311 | */ |
315 | 312 | setCurrentTime: function( time , callback, callbackCount ) { |
316 | 313 | var _this = this; |
317 | | - if( !callbackCount ) |
| 314 | + if( !callbackCount ){ |
318 | 315 | 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 ){ |
344 | 322 | mw.log("Error with seek request, media never in ready state"); |
345 | 323 | return ; |
346 | 324 | } |
347 | 325 | setTimeout( function(){ |
348 | 326 | _this.setCurrentTime( time, callback , callbackCount++); |
349 | | - }, 10 ); |
| 327 | + }, 100 ); |
| 328 | + return ; |
350 | 329 | } |
| 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 | + } |
351 | 356 | }, |
352 | 357 | |
353 | 358 | /** |