@@ -132,6 +132,13 @@ Phaser.Video = function (game, key) {
132132 */
133133 this . _paused = false ;
134134
135+ /**
136+ * @property {boolean } _pending - Internal var tracking play pending.
137+ * @private
138+ * @default
139+ */
140+ this . _pending = false ;
141+
135142 if ( ! this . game . device . cocoonJS && this . game . device . iOS || ( window [ 'PhaserGlobal' ] && window [ 'PhaserGlobal' ] . fakeiOSTouchLock ) )
136143 {
137144 this . setTouchLock ( ) ;
@@ -214,9 +221,19 @@ Phaser.Video.prototype = {
214221 }
215222
216223 this . video . playbackRate = playbackRate ;
217- this . video . play ( ) ;
218224
219- this . onPlay . dispatch ( this , loop , playbackRate ) ;
225+ if ( this . touchLocked )
226+ {
227+ this . _pending = true ;
228+ }
229+ else
230+ {
231+ this . _pending = false ;
232+
233+ this . video . play ( ) ;
234+
235+ this . onPlay . dispatch ( this , loop , playbackRate ) ;
236+ }
220237
221238 return this ;
222239
@@ -247,7 +264,14 @@ Phaser.Video.prototype = {
247264
248265 this . video . removeEventListener ( 'ended' , this . complete . bind ( this ) ) ;
249266
250- this . video . pause ( ) ;
267+ if ( this . touchLocked )
268+ {
269+ this . _pending = false ;
270+ }
271+ else
272+ {
273+ this . video . pause ( ) ;
274+ }
251275
252276 return this ;
253277
@@ -370,7 +394,7 @@ Phaser.Video.prototype = {
370394 */
371395 setPause : function ( ) {
372396
373- if ( this . _paused )
397+ if ( this . _paused || this . touchLocked )
374398 {
375399 return ;
376400 }
@@ -389,7 +413,7 @@ Phaser.Video.prototype = {
389413 */
390414 setResume : function ( ) {
391415
392- if ( ! this . _paused || this . _codePaused )
416+ if ( ! this . _paused || this . _codePaused || this . touchLocked )
393417 {
394418 return ;
395419 }
@@ -417,26 +441,55 @@ Phaser.Video.prototype = {
417441 */
418442 changeSource : function ( src , autoplay ) {
419443
420-
444+ this . video . src = src ;
421445
422446 return this ;
423447
424448 } ,
425449
426450 /**
427- * Sets the Input Manager touch callback to be SoundManager .unlock.
428- * Required for iOS audio device unlocking. Mostly just used internally.
451+ * Sets the Input Manager touch callback to be Video .unlock.
452+ * Required for iOS video unlocking. Mostly just used internally.
429453 *
430454 * @method Phaser.Video#setTouchLock
431455 */
432456 setTouchLock : function ( ) {
433457
434- this . game . input . touch . callbackContext = this ;
435- this . game . input . touch . touchStartCallback = this . unlock ;
458+ // this.game.input.touch.callbackContext = this;
459+ // this.game.input.touch.touchStartCallback = this.unlock;
460+ this . game . input . touch . addTouchLockCallback ( this . unlock , this ) ;
436461 this . touchLocked = true ;
437462
438463 } ,
439464
465+ /**
466+ * Enables the video on mobile devices, usually after the first touch.
467+ * If the SoundManager hasn't been unlocked then this will automatically unlock that as well.
468+ * Only one video can be pending unlock at any one time.
469+ *
470+ * @method Phaser.Video#unlock
471+ */
472+ unlock : function ( ) {
473+
474+ // We can remove the event because we've done what we needed (started the unlock sound playing)
475+ // this.game.input.touch.callbackContext = null;
476+ // this.game.input.touch.touchStartCallback = null;
477+
478+ this . touchLocked = false ;
479+
480+ // if (this.game.sound && this.game.sound.touchLocked)
481+ // {
482+ // this.game.sound.unlock();
483+ // }
484+
485+ this . video . play ( ) ;
486+
487+ this . onPlay . dispatch ( this , this . loop , this . playbackRate ) ;
488+
489+ return true ;
490+
491+ } ,
492+
440493 /**
441494 * Destroys the Video object. This calls Video.stop(), then sets the Video src to a blank string and nulls the reference.
442495 * If any Sprites are using this Video as their texture it is up to you to manage those.
@@ -546,8 +599,11 @@ Object.defineProperty(Phaser.Video.prototype, "mute", {
546599} ) ;
547600
548601/**
602+ * Gets or sets the paused state of the Video.
603+ * If the video is still touch locked (such as on iOS devices) this call has no effect.
604+ *
549605* @name Phaser.Video#paused
550- * @property {boolean } paused - Gets or sets the paused state of the Video.
606+ * @property {boolean } paused
551607*/
552608Object . defineProperty ( Phaser . Video . prototype , "paused" , {
553609
@@ -561,6 +617,11 @@ Object.defineProperty(Phaser.Video.prototype, "paused", {
561617
562618 value = value || null ;
563619
620+ if ( this . touchLocked )
621+ {
622+ return ;
623+ }
624+
564625 if ( value )
565626 {
566627 if ( this . _paused )
@@ -634,6 +695,36 @@ Object.defineProperty(Phaser.Video.prototype, "playbackRate", {
634695
635696} ) ;
636697
698+ /**
699+ * Gets or sets if the Video is set to loop.
700+ * Please note that at present some browsers (i.e. Chrome) do not support *seamless* video looping.
701+ *
702+ * @name Phaser.Video#loop
703+ * @property {number } loop
704+ */
705+ Object . defineProperty ( Phaser . Video . prototype , "loop" , {
706+
707+ get : function ( ) {
708+
709+ return this . video . loop ;
710+
711+ } ,
712+
713+ set : function ( value ) {
714+
715+ if ( value )
716+ {
717+ this . video . loop = 'loop' ;
718+ }
719+ else
720+ {
721+ this . video . loop = '' ;
722+ }
723+
724+ }
725+
726+ } ) ;
727+
637728/**
638729* @name Phaser.Video#playing
639730* @property {boolean } playing - True if the video is currently playing (and not paused or ended), otherwise false.
0 commit comments