From c8bbea552d8087f4c7f78ff694f188b7bf6d1bca Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Fri, 13 Apr 2018 12:53:03 +0100 Subject: [PATCH] Fixed issue in HTMLAudioSound where `mute` would get into a recursive loop. --- CHANGELOG.md | 5 +++ src/sound/BaseSound.js | 52 ++--------------------------- src/sound/html5/HTML5AudioSound.js | 19 ++++++----- src/sound/webaudio/WebAudioSound.js | 14 +++++--- 4 files changed, 26 insertions(+), 64 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a17fb0557..7197a7712 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ * DynamicBitmapText was missing the `letterSpacing` property, causing it to only render the first character in WebGL (thanks @Antriel) * The Animation component didn't properly check for the animation state in its update, causing pause / resume to fail. Fix #3556 (thanks @Antriel @siolfyr) * The Scene Manager would never reach an `isBooted` state if you didn't add any Scenes into the Game Config. Fix #3553 (thanks @rgk) +* Fixed issue in HTMLAudioSound where `mute` would get into a recursive loop. + +### Updates + +* Removed the following properties from BaseSound as they are no longer required. Each class that extends BaseSound implements them directly as getters: `mute`, `loop`, `seek` and `volume`. ### Examples, Documentation and TypeScript diff --git a/src/sound/BaseSound.js b/src/sound/BaseSound.js index 942ff4f28..af7b59db4 100644 --- a/src/sound/BaseSound.js +++ b/src/sound/BaseSound.js @@ -144,51 +144,6 @@ var BaseSound = new Class({ this.config = Extend(this.config, config); - /** - * Boolean indicating whether the sound is muted or not. - * Gets or sets the muted state of this sound. - * - * @name Phaser.Sound.BaseSound#mute - * @type {boolean} - * @default false - * @since 3.0.0 - */ - this.mute = false; - - /** - * Gets or sets the volume of this sound, - * a value between 0 (silence) and 1 (full volume). - * - * @name Phaser.Sound.BaseSound#volume - * @type {number} - * @default 1 - * @since 3.0.0 - */ - this.volume = 1; - - /** - * Property representing the position of playback for this sound, in seconds. - * Setting it to a specific value moves current playback to that position. - * The value given is clamped to the range 0 to current marker duration. - * Setting seek of a stopped sound has no effect. - * - * @name Phaser.Sound.BaseSound#seek - * @type {number} - * @default 0 - * @since 3.0.0 - */ - this.seek = 0; - - /** - * Flag indicating whether or not the sound or current sound marker will loop. - * - * @name Phaser.Sound.BaseSound#loop - * @type {boolean} - * @default false - * @since 3.0.0 - */ - this.loop = false; - /** * Object containing markers definitions. * @@ -290,7 +245,7 @@ var BaseSound = new Class({ if (!this.markers[marker.name]) { // eslint-disable-next-line no-console - console.error('updateMarker - Marker with name \'' + marker.name + '\' does not exist for sound \'' + this.key + '\'!'); + console.warn('Audio Marker: ' + marker.name + ' missing in Sound: ' + this.key); return false; } @@ -349,9 +304,6 @@ var BaseSound = new Class({ if (typeof markerName !== 'string') { - // eslint-disable-next-line no-console - console.error('Sound marker name has to be a string!'); - return false; } @@ -366,7 +318,7 @@ var BaseSound = new Class({ if (!this.markers[markerName]) { // eslint-disable-next-line no-console - console.error('No marker with name \'' + markerName + '\' found for sound \'' + this.key + '\'!'); + console.warn('Marker: ' + markerName + ' missing in Sound: ' + this.key); return false; } diff --git a/src/sound/html5/HTML5AudioSound.js b/src/sound/html5/HTML5AudioSound.js index ea4ce2f8a..40e9a03c1 100644 --- a/src/sound/html5/HTML5AudioSound.js +++ b/src/sound/html5/HTML5AudioSound.js @@ -47,7 +47,7 @@ var HTML5AudioSound = new Class({ if (!this.tags) { // eslint-disable-next-line no-console - console.error('No audio loaded in cache with key: \'' + key + '\'!'); + console.warn('Audio cache entry missing: ' + key); return; } @@ -119,6 +119,7 @@ var HTML5AudioSound = new Class({ { return false; } + if (!BaseSound.prototype.play.call(this, markerName, config)) { return false; @@ -610,7 +611,8 @@ var HTML5AudioSound = new Class({ */ /** - * [description] + * Boolean indicating whether the sound is muted or not. + * Gets or sets the muted state of this sound. * * @name Phaser.Sound.HTML5AudioSound#mute * @type {boolean} @@ -633,8 +635,6 @@ var HTML5AudioSound = new Class({ return; } - this.setMute(); - this.emit('mute', this, value); } }, @@ -664,7 +664,7 @@ var HTML5AudioSound = new Class({ */ /** - * [description] + * Gets or sets the volume of this sound, a value between 0 (silence) and 1 (full volume). * * @name Phaser.Sound.HTML5AudioSound#volume * @type {number} @@ -687,8 +687,6 @@ var HTML5AudioSound = new Class({ return; } - this.setVolume(); - this.emit('volume', this, value); } }, @@ -839,7 +837,10 @@ var HTML5AudioSound = new Class({ */ /** - * [description] + * Property representing the position of playback for this sound, in seconds. + * Setting it to a specific value moves current playback to that position. + * The value given is clamped to the range 0 to current marker duration. + * Setting seek of a stopped sound has no effect. * * @name Phaser.Sound.HTML5AudioSound#seek * @type {number} @@ -919,7 +920,7 @@ var HTML5AudioSound = new Class({ */ /** - * [description] + * Flag indicating whether or not the sound or current sound marker will loop. * * @name Phaser.Sound.HTML5AudioSound#loop * @type {boolean} diff --git a/src/sound/webaudio/WebAudioSound.js b/src/sound/webaudio/WebAudioSound.js index 00da6b490..b8e3e6991 100644 --- a/src/sound/webaudio/WebAudioSound.js +++ b/src/sound/webaudio/WebAudioSound.js @@ -45,7 +45,7 @@ var WebAudioSound = new Class({ if (!this.audioBuffer) { // eslint-disable-next-line no-console - console.error('No audio loaded in cache with key: \'' + key + '\'!'); + console.warn('Audio cache entry missing: ' + key); return; } @@ -727,7 +727,8 @@ var WebAudioSound = new Class({ */ /** - * [description] + * Boolean indicating whether the sound is muted or not. + * Gets or sets the muted state of this sound. * * @name Phaser.Sound.WebAudioSound#mute * @type {boolean} @@ -776,7 +777,7 @@ var WebAudioSound = new Class({ */ /** - * [description] + * Gets or sets the volume of this sound, a value between 0 (silence) and 1 (full volume). * * @name Phaser.Sound.WebAudioSound#volume * @type {number} @@ -824,7 +825,10 @@ var WebAudioSound = new Class({ */ /** - * [description] + * Property representing the position of playback for this sound, in seconds. + * Setting it to a specific value moves current playback to that position. + * The value given is clamped to the range 0 to current marker duration. + * Setting seek of a stopped sound has no effect. * * @name Phaser.Sound.WebAudioSound#seek * @type {number} @@ -902,7 +906,7 @@ var WebAudioSound = new Class({ */ /** - * [description] + * Flag indicating whether or not the sound or current sound marker will loop. * * @name Phaser.Sound.WebAudioSound#loop * @type {boolean}