If you called Video.changeSource, and then immediately called Video.play after it, it would fire the onComplete event twice (thanks @jaraiza #2543)

This commit is contained in:
Richard Davey 2016-09-26 23:28:41 +01:00
parent f331697fee
commit 0692bf01b5
2 changed files with 21 additions and 3 deletions

View file

@ -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

View file

@ -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();
}