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.
This commit is contained in:
photonstorm 2015-04-17 03:49:20 +01:00
parent 8144c4910e
commit 59beae762d
2 changed files with 40 additions and 15 deletions

View file

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

View file

@ -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;
}
if (this.context !== null)
else
{
this.usingAudioTag = true;
}
}
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])