Sound.restart and Sound.stop now properly disconnect the sound from the gainNode (or external node) before stopping it, allowing restart to work correctly (thanks @eofs #1796)

This commit is contained in:
photonstorm 2015-06-16 16:24:47 +01:00
parent 00cf44eb22
commit 1990bce48b
2 changed files with 23 additions and 22 deletions

View file

@ -386,6 +386,7 @@ Version 2.4 - "Katar" - in dev
* Sound.resume wouldn't properly restart looped sounds in Chrome after being paused. Phaser now specifically handles the Chrome 42 bug and later fix (thanks @nkovacs #1820)
* Setting the BitmapText.maxWidth property would throw an error (thanks @drhayes #1807)
* If running under Cordova and iOS the Game.lockRender boolean will be set to `true` when the game pauses and `false` when it resumes. This avoids the `gpus_ReturnNotPermittedKillClient` app crash on iOS (thanks @cncolder #1800)
* Sound.restart and Sound.stop now properly disconnect the sound from the gainNode (or external node) before stopping it, allowing restart to work correctly (thanks @eofs #1796)
For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md).

View file

@ -426,8 +426,6 @@ Phaser.Sound.prototype = {
{
if (this.loop)
{
// console.log('Sound update loop: ' + this.currentTime + ' m: ' + this.currentMarker);
// won't work with markers, needs to reset the position
this.onLoop.dispatch(this);
@ -453,8 +451,6 @@ Phaser.Sound.prototype = {
}
else
{
// console.log('Sound update stop: ' + this.currentTime + ' m: ' + this.currentMarker);
if (this.loop)
{
this.onLoop.dispatch(this);
@ -498,8 +494,6 @@ Phaser.Sound.prototype = {
if (typeof marker === 'undefined' || marker === false || marker === null) { marker = ''; }
if (typeof forceRestart === 'undefined') { forceRestart = true; }
// console.log('Sound play: ' + marker);
if (this.isPlaying && !this.allowMultiple && !forceRestart && !this.override)
{
// Use Restart instead
@ -510,6 +504,15 @@ Phaser.Sound.prototype = {
{
if (this.usingWebAudio)
{
if (this.externalNode)
{
this._sound.disconnect(this.externalNode);
}
else
{
this._sound.disconnect(this.gainNode);
}
if (typeof this._sound.stop === 'undefined')
{
this._sound.noteOff(0);
@ -564,8 +567,6 @@ Phaser.Sound.prototype = {
this._tempPosition = this.position;
this._tempVolume = this.volume;
this._tempLoop = this.loop;
// console.log('Marker pos: ' + this.position + ' duration: ' + this.duration + ' ms: ' + this.durationMS);
}
else
{
@ -597,14 +598,7 @@ Phaser.Sound.prototype = {
// Does the sound need decoding?
if (this.game.cache.isSoundDecoded(this.key))
{
// Do we need to do this every time we play? How about just if the buffer is empty?
if (this._buffer === null)
{
this._buffer = this.game.cache.getSoundData(this.key);
}
this._sound = this.context.createBufferSource();
this._sound.buffer = this._buffer;
if (this.externalNode)
{
@ -615,6 +609,9 @@ Phaser.Sound.prototype = {
this._sound.connect(this.gainNode);
}
this._buffer = this.game.cache.getSoundData(this.key);
this._sound.buffer = this._buffer;
if (this.loop && marker === '')
{
this._sound.loop = true;
@ -627,11 +624,8 @@ Phaser.Sound.prototype = {
this.totalDuration = this._sound.buffer.duration;
// console.log('dur', this._sound.buffer.duration, Math.ceil(this._sound.buffer.duration * 1000));
if (this.duration === 0)
{
// console.log('duration reset');
this.duration = this.totalDuration;
this.durationMS = Math.ceil(this.totalDuration * 1000);
}
@ -640,13 +634,12 @@ Phaser.Sound.prototype = {
if (typeof this._sound.start === 'undefined')
{
this._sound.noteGrainOn(0, this.position, this.duration);
//this._sound.noteOn(0); // the zero is vitally important, crashes iOS6 without it
}
else
{
if (this.loop && marker === '')
{
this._sound.start(0);
this._sound.start(0, 0);
}
else
{
@ -708,8 +701,6 @@ Phaser.Sound.prototype = {
this.currentTime = 0;
this.stopTime = this.startTime + this.durationMS;
this.onPlay.dispatch(this);
// console.log('stopTime: ' + this.stopTime + ' rs: ' + this._sound.readyState);
}
else
{
@ -846,6 +837,15 @@ Phaser.Sound.prototype = {
{
if (this.usingWebAudio)
{
if (this.externalNode)
{
this._sound.disconnect(this.externalNode);
}
else
{
this._sound.disconnect(this.gainNode);
}
if (typeof this._sound.stop === 'undefined')
{
this._sound.noteOff(0);