Fixed a bug stopping legacy Audio from starting correctly. Also fixed an issue in the Loader causing it to not load the next file if an unsupported audio file was encountered. Fixed audio playback issues on Firefox/Waterfox as a result.

This commit is contained in:
Richard Davey
2013-09-11 11:33:27 +01:00
parent e79dd5856d
commit 87858d6bbf
9 changed files with 722 additions and 752 deletions
+3 -3
View File
@@ -76,7 +76,7 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant
* The Pixi Renderer
* @type {number}
*/
this.renderType = renderer;
this.renderer = null;
/**
* The StateManager.
@@ -94,7 +94,7 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant
* The Renderer this Phaser.Game will use. Either Phaser.RENDERER_AUTO, Phaser.RENDERER_CANVAS or Phaser.RENDERER_WEBGL
* @type {number}
*/
this.renderType = 0;
this.renderType = renderer;
/**
* Whether load complete loading or not.
@@ -334,7 +334,7 @@ Phaser.Game.prototype = {
setUpRenderer: function () {
if (this.renderType == Phaser.CANVAS || (this.renderType == Phaser.AUTO && this.device.webGL == false))
if (this.renderType === Phaser.CANVAS || (this.renderType === Phaser.AUTO && this.device.webGL == false))
{
if (this.device.canvas)
{
+2
View File
@@ -49,6 +49,8 @@ Phaser.Cache = function (game) {
this.addDefaultImage();
this.onSoundUnlock = new Phaser.Signal;
};
Phaser.Cache.prototype = {
+5 -1
View File
@@ -471,7 +471,7 @@ Phaser.Loader.prototype = {
{
if (this.game.sound.touchLocked)
{
// If audio is locked we can't do this yet, so need to queue this load request somehow. Bum.
// If audio is locked we can't do this yet, so need to queue this load request. Bum.
file.data = new Audio();
file.data.name = file.key;
file.data.preload = 'auto';
@@ -492,6 +492,10 @@ Phaser.Loader.prototype = {
}
}
}
else
{
this.fileError(file.key);
}
break;
+24 -12
View File
@@ -56,10 +56,15 @@ Phaser.Sound = function (game, key, volume, loop) {
}
else
{
if (this.game.cache.getSound(key) && this.game.cache.getSound(key).locked == false)
if (this.game.cache.getSound(key) && this.game.cache.isSoundReady(key))
{
this._sound = this.game.cache.getSoundData(key);
this.totalDuration = this._sound.duration;
this.totalDuration = 0;
if (this._sound.duration)
{
this.totalDuration = this._sound.duration;
}
}
else
{
@@ -86,7 +91,7 @@ Phaser.Sound.prototype = {
{
this._sound = this.game.cache.getSoundData(this.key);
this.totalDuration = this._sound.duration;
// console.log('sound has unlocked' + this._sound);
console.log('sound has unlocked' + this._sound);
}
},
@@ -298,24 +303,28 @@ Phaser.Sound.prototype = {
}
else
{
//console.log('Sound play Audio');
// console.log('Sound play Audio');
if (this.game.cache.getSound(this.key) && this.game.cache.getSound(this.key).locked)
{
//console.log('tried playing locked sound, pending set, reload started');
// console.log('tried playing locked sound, pending set, reload started');
this.game.cache.reloadSound(this.key);
this.pendingPlayback = true;
}
else
{
//console.log('sound not locked, state?', this._sound.readyState);
// console.log('sound not locked, state?', this._sound.readyState);
if (this._sound && this._sound.readyState == 4)
{
this._sound.play();
// This doesn't become available until you call play(), wonderful ...
this.totalDuration = this._sound.duration;
if (this.duration == 0)
{
this.duration = this.totalDuration * 1000;
}
//console.log('playing', this._sound);
// console.log('playing', this._sound);
this._sound.currentTime = this.position;
this._sound.muted = this._muted;
@@ -328,7 +337,6 @@ Phaser.Sound.prototype = {
this._sound.volume = this._volume;
}
this._sound.play();
this.isPlaying = true;
this.startTime = this.game.time.now;
this.currentTime = 0;
@@ -507,15 +515,19 @@ Object.defineProperty(Phaser.Sound.prototype, "volume", {
set: function (value) {
this._volume = value;
if (this.usingWebAudio)
{
this._volume = value;
this.gainNode.gain.value = value;
}
else if(this.usingAudioTag && this._sound)
else if (this.usingAudioTag && this._sound)
{
this._sound.volume = value;
// Causes an Index size error in Firefox if you don't clamp the value
if (value >= 0 && value <= 1)
{
this._volume = value;
this._sound.volume = value;
}
}
},
+9 -2
View File
@@ -105,9 +105,16 @@ Phaser.Canvas = {
parent = parent || '';
overflowHidden = overflowHidden || true;
if ((parent !== '' || parent !== null) && document.getElementById(parent))
if (parent !== '')
{
document.getElementById(parent).appendChild(canvas);
if (document.getElementById(parent))
{
document.getElementById(parent).appendChild(canvas);
}
else
{
document.body.appendChild(canvas);
}
if (overflowHidden)
{