@@ -215,6 +215,8 @@ var Video = new Class({
215215 */
216216 this . _crop = this . resetCropObject ( ) ;
217217
218+ this . _textureState = 0 ;
219+
218220 this . setTexture ( textureKey ) ;
219221 this . setPosition ( x , y ) ;
220222 this . setSizeToFrame ( ) ;
@@ -296,6 +298,8 @@ var Video = new Class({
296298
297299 if ( this . touchLocked )
298300 {
301+ console . log ( 'TL bail out' ) ;
302+
299303 this . _pending = true ;
300304 }
301305 else
@@ -305,28 +309,63 @@ var Video = new Class({
305309 if ( this . video . readyState !== 4 )
306310 {
307311 this . retry = this . retryLimit ;
312+
308313 this . _retryID = window . setTimeout ( this . checkVideoProgress . bind ( this ) , this . retryInterval ) ;
314+
315+ this . video . play ( ) ;
309316 }
310317 else
311318 {
319+ this . _textureState = 0 ;
312320 this . _setPlay = false ;
313321 this . _setUpdate = false ;
314322
315323 this . _playCallback = this . playHandler . bind ( this ) ;
316324 this . _timeUpdateCallback = this . timeUpdateHandler . bind ( this ) ;
317325
318- this . video . addEventListener ( 'playing' , this . _playCallback , true ) ;
319326 this . video . addEventListener ( 'timeupdate' , this . _timeUpdateCallback , true ) ;
320- }
321327
322- this . video . play ( ) ;
328+ if ( typeof Promise !== 'undefined' )
329+ {
330+ console . log ( 'video play promise' ) ;
323331
324- // this.onPlay.dispatch(this, loop, playbackRate);
332+ this . video . play ( )
333+ . then ( this . playSuccessHandler . bind ( this ) )
334+ . catch ( this . playErrorHandler . bind ( this ) ) ;
335+ }
336+ else
337+ {
338+ this . video . addEventListener ( 'playing' , this . _playCallback , true ) ;
339+
340+ // this.video.addEventListener('timeupdate', this._timeUpdateCallback, true);
341+
342+ this . video . play ( ) ;
343+ }
344+ }
325345 }
326346
327347 return this ;
328348 } ,
329349
350+ playSuccessHandler : function ( )
351+ {
352+ console . log ( 'playSuccessHandler' ) ;
353+
354+ if ( this . _textureState === 0 )
355+ {
356+ this . _textureState = 1 ;
357+ }
358+ else
359+ {
360+ this . _textureState = 2 ;
361+ }
362+ } ,
363+
364+ playErrorHandler : function ( )
365+ {
366+ console . log ( 'playErrorHandler' ) ;
367+ } ,
368+
330369 /**
331370 * Called when the video completes playback (reaches and ended state).
332371 * Dispatches the Video.onComplete signal.
@@ -342,22 +381,38 @@ var Video = new Class({
342381
343382 timeUpdateHandler : function ( )
344383 {
345- if ( ! this . _setUpdate )
346- {
384+ // if (!this._setUpdate)
385+ // {
347386 console . log ( '>>> timeUpdateHandler <<<' ) ;
348387
349- this . _setUpdate = true ;
388+ // this._setUpdate = true;
350389
351- // this.video.removeEventListener('timeupdate', this._timeUpdateCallback, true);
352-
353- if ( this . _setPlay && this . _setUpdate )
390+ if ( this . _textureState === 1 )
354391 {
355- this . updateTexture ( ) ;
356-
357- this . texture = this . videoTexture ;
358- this . frame = this . videoTexture . get ( ) ;
392+ console . log ( '>>> timeUpdateHandler completed <<<' ) ;
393+
394+ this . video . removeEventListener ( 'timeupdate' , this . _timeUpdateCallback , true ) ;
395+
396+ this . _textureState = 2 ;
359397 }
360- }
398+ else if ( this . _textureState === 0 )
399+ {
400+ console . log ( '>>> timeUpdateHandler called before play handler <<<' ) ;
401+
402+ this . video . removeEventListener ( 'timeupdate' , this . _timeUpdateCallback , true ) ;
403+
404+ this . _textureState = 1 ;
405+ }
406+
407+ // if (this._setPlay && this._setUpdate)
408+ // {
409+ // this._textureState = 2;
410+
411+ // console.log('>>> timeUpdateHandler ---- swap it <<<');
412+
413+ // this.playSuccessHandler();
414+ // }
415+ // }
361416 } ,
362417
363418 /**
@@ -368,18 +423,21 @@ var Video = new Class({
368423 */
369424 playHandler : function ( )
370425 {
371- console . log ( '>>> playHandler <<<' ) ;
372-
373- this . _setPlay = true ;
374-
375- this . video . removeEventListener ( 'playing' , this . _playCallback , true ) ;
376-
377- if ( this . _setPlay && this . _setUpdate )
426+ if ( ! this . _setPlay )
378427 {
379- this . updateTexture ( ) ;
428+ console . log ( '>>> playHandler <<<' ) ;
429+
430+ this . _setPlay = true ;
431+
432+ this . video . removeEventListener ( 'playing' , this . _playCallback , true ) ;
433+
434+ if ( this . _setPlay && this . _setUpdate )
435+ {
436+ this . texture = this . videoTexture ;
437+ this . frame = this . videoTexture . get ( ) ;
380438
381- this . texture = this . videoTexture ;
382- this . frame = this . videoTexture . get ( ) ;
439+ // this.playSuccessHandler() ;
440+ }
383441 }
384442 } ,
385443
@@ -575,7 +633,7 @@ var Video = new Class({
575633 // First we'll update our current CanvasTexture
576634 if ( newSize )
577635 {
578- this . snapshot . setSize ( width , height ) ;
636+ // this.snapshot.setSize(width, height);
579637 }
580638
581639 if ( ! this . videoTexture )
@@ -597,21 +655,26 @@ var Video = new Class({
597655 textureSource . height = height ;
598656 }
599657
600- // this.texture = this.videoTexture;
601- // this.frame = this.videoTexture.get();
602-
603- this . setSizeToFrame ( ) ;
604- this . setOriginFromFrame ( ) ;
605-
606- // if (this._autoplay)
607- // {
608- // this.video.play();
609- // }
658+ // this.setSizeToFrame();
659+ // this.setOriginFromFrame();
610660 } ,
611661
612662 preUpdate : function ( )
613663 {
614- if ( this . videoTextureSource && this . playing )
664+ if ( this . _textureState === 2 )
665+ {
666+ this . updateTexture ( ) ;
667+
668+ this . texture = this . videoTexture ;
669+ this . frame = this . videoTexture . get ( ) ;
670+
671+ this . setSizeToFrame ( ) ;
672+ this . setOriginFromFrame ( ) ;
673+
674+ this . _textureState = 3 ;
675+ }
676+
677+ if ( this . _textureState === 3 && this . playing )
615678 {
616679 this . videoTextureSource . update ( ) ;
617680 }
0 commit comments