From 59beae762dd57ca086d7af7063282bd5c21a57d8 Mon Sep 17 00:00:00 2001 From: photonstorm Date: Fri, 17 Apr 2015 03:49:20 +0100 Subject: [PATCH] The SoundManager didn't accurately detect devices or browser environments with no sound card present and would try to carry on using a null Web Audio context (thanks @englercj #1746) SoundManager.pauseAll, resumeAll and stopAll now checks if the SoundManager.noAudio is set and ignores the calls. SoundManager.usingWebAudio is set to `false` by default (used to be `true`) and is only explicitly set if Web Audio is available and hasn't been disabled in the PhaserGlobal object. SoundManager.touchLocked is now set to `false` should the device be using legacy Audio, avoiding the unlock call running without need. --- README.md | 4 +++ src/sound/SoundManager.js | 51 +++++++++++++++++++++++++++------------ 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 662871ba7..2b0cd6971 100644 --- a/README.md +++ b/README.md @@ -282,6 +282,9 @@ Version 2.4 - "Katar" - in dev * RenderTexture.render and `renderXY` would ignore the Sprites rotation or scale. The full Sprite transform is now used correctly when the Sprite is drawn to the texture. If you wish to replicate the old behavior please use `RenderTexture.renderRawXY` instead. * Pixi.Sprite.renderCanvas and renderWebGL now has a new optional matrix parameter. You can use this to render the Sprite with an alternative transform matrix without actually adjusting the Sprite matrix at all. * RenderTexture.matrix has been removed as it's no longer used. +* SoundManager.pauseAll, resumeAll and stopAll now checks if the SoundManager.noAudio is set and ignores the calls. +* SoundManager.usingWebAudio is set to `false` by default (used to be `true`) and is only explicitly set if Web Audio is available and hasn't been disabled in the PhaserGlobal object. +* SoundManager.touchLocked is now set to `false` should the device be using legacy Audio, avoiding the unlock call running without need. ### Bug Fixes @@ -303,6 +306,7 @@ Version 2.4 - "Katar" - in dev * Added the missing `preRender` function to the Phaser.State class template. * Fixed bug in Pixi where RenderTexture.render would ignore the given matrix. * Fixed a bug in Pixi where drawing a Sprite to a RenderTexture would reset the Sprites transform to an identity Matrix. +* The SoundManager didn't accurately detect devices or browser environments with no sound card present and would try to carry on using a null Web Audio context (thanks @englercj #1746) For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md). diff --git a/src/sound/SoundManager.js b/src/sound/SoundManager.js index d03d006c9..1a81923b2 100644 --- a/src/sound/SoundManager.js +++ b/src/sound/SoundManager.js @@ -95,19 +95,19 @@ Phaser.SoundManager = function (game) { this.context = null; /** - * @property {boolean} usingWebAudio - true if this sound is being played with Web Audio. + * @property {boolean} usingWebAudio - True the SoundManager and device are both using Web Audio. * @readonly */ - this.usingWebAudio = true; + this.usingWebAudio = false; /** - * @property {boolean} usingAudioTag - true if the sound is being played via the Audio tag. + * @property {boolean} usingAudioTag - True the SoundManager and device are both using the Audio tag instead of Web Audio. * @readonly */ this.usingAudioTag = false; /** - * @property {boolean} noAudio - Has audio been disabled via the PhaserGlobal object? Useful if you need to use a 3rd party audio library instead. + * @property {boolean} noAudio - True if audio been disabled via the PhaserGlobal (useful if you need to use a 3rd party audio library) or the device doesn't support any audio. * @default */ this.noAudio = false; @@ -159,22 +159,22 @@ Phaser.SoundManager.prototype = { this.touchLocked = false; } + // PhaserGlobal overrides if (window['PhaserGlobal']) { // Check to see if all audio playback is disabled (i.e. handled by a 3rd party class) if (window['PhaserGlobal'].disableAudio === true) { - this.usingWebAudio = false; this.noAudio = true; + this.touchLocked = false; return; } // Check if the Web Audio API is disabled (for testing Audio Tag playback during development) if (window['PhaserGlobal'].disableWebAudio === true) { - this.usingWebAudio = false; this.usingAudioTag = true; - this.noAudio = false; + this.touchLocked = false; return; } } @@ -192,7 +192,7 @@ Phaser.SoundManager.prototype = { } catch (error) { this.context = null; this.usingWebAudio = false; - this.noAudio = true; + this.touchLocked = false; } } else if (!!window['webkitAudioContext']) @@ -202,19 +202,25 @@ Phaser.SoundManager.prototype = { } catch (error) { this.context = null; this.usingWebAudio = false; - this.noAudio = true; + this.touchLocked = false; } } } - if (!!window['Audio'] && this.context === null) + if (this.context === null) { - this.usingWebAudio = false; - this.usingAudioTag = true; - this.noAudio = false; + // No Web Audio support - how about legacy Audio? + if (!!window['Audio']) + { + this.noAudio = true; + return; + } + else + { + this.usingAudioTag = true; + } } - - if (this.context !== null) + else { if (typeof this.context.createGain === 'undefined') { @@ -280,6 +286,11 @@ Phaser.SoundManager.prototype = { */ stopAll: function () { + if (this.noAudio) + { + return; + } + for (var i = 0; i < this._sounds.length; i++) { if (this._sounds[i]) @@ -297,6 +308,11 @@ Phaser.SoundManager.prototype = { */ pauseAll: function () { + if (this.noAudio) + { + return; + } + for (var i = 0; i < this._sounds.length; i++) { if (this._sounds[i]) @@ -314,6 +330,11 @@ Phaser.SoundManager.prototype = { */ resumeAll: function () { + if (this.noAudio) + { + return; + } + for (var i = 0; i < this._sounds.length; i++) { if (this._sounds[i])