From 0692bf01b53915199a9f71509ecd2a7249ed7af1 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Mon, 26 Sep 2016 23:28:41 +0100 Subject: [PATCH] If you called Video.changeSource, and then immediately called Video.play after it, it would fire the `onComplete` event twice (thanks @jaraiza #2543) --- README.md | 1 + src/gameobjects/Video.js | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5eb618aac..da3ae885a 100644 --- a/README.md +++ b/README.md @@ -338,6 +338,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/ * The Weapon Plugin will no longer crash if the Weapon's bullets have not yet been initialized before setting a new bullet class (thanks @JTronLabs #2731) * Groups with `fixedToCamera` set on them now factor in the camera scale (thanks @kevinAlbs #2771) * Text.width and Text.height now divide the result by the Text.resolution, to avoid incorrect dimensions on High DPI devices (thanks @mattahj #2146) +* If you called Video.changeSource, and then immediately called Video.play after it, it would fire the `onComplete` event twice (thanks @jaraiza #2543) ### Pixi Updates diff --git a/src/gameobjects/Video.js b/src/gameobjects/Video.js index 4c69903c6..5b238cb7e 100644 --- a/src/gameobjects/Video.js +++ b/src/gameobjects/Video.js @@ -201,6 +201,13 @@ Phaser.Video = function (game, key, url) { */ this._pending = false; + /** + * @property {boolean} _pendingChangeSource - Internal var tracking play pending. + * @private + * @default + */ + this._pendingChangeSource = false; + /** * @property {boolean} _autoplay - Internal var tracking autoplay when changing source. * @private @@ -633,7 +640,9 @@ Phaser.Video.prototype = { }, /** - * Starts this video playing if it's not already doing so. + * Starts this video playing. + * + * If the video is already playing, or has been queued to play with `changeSource` then this method just returns. * * @method Phaser.Video#play * @param {boolean} [loop=false] - Should the video loop automatically when it reaches the end? Please note that at present some browsers (i.e. Chrome) do not support *seamless* video looping. @@ -642,6 +651,11 @@ Phaser.Video.prototype = { */ play: function (loop, playbackRate) { + if (this._pendingChangeSource) + { + return this; + } + if (loop === undefined) { loop = false; } if (playbackRate === undefined) { playbackRate = 1; } @@ -756,7 +770,7 @@ Phaser.Video.prototype = { } else { - this.video.src = ""; + this.video.src = ''; if (this.videoStream['active']) { @@ -774,7 +788,6 @@ Phaser.Video.prototype = { { this.videoStream.stop(); } - } } @@ -981,6 +994,8 @@ Phaser.Video.prototype = { this.video.pause(); + this._pendingChangeSource = true; + this.retry = this.retryLimit; this._retryID = window.setTimeout(this.checkVideoProgress.bind(this), this.retryInterval); @@ -1011,6 +1026,8 @@ Phaser.Video.prototype = { // if (this.video.readyState === 2 || this.video.readyState === 4) if (this.video.readyState === 4) { + this._pendingChangeSource = false; + // We've got enough data to update the texture for playback this.updateTexture(); }