From 2433844cd3b72a63205ce7749458023b8141539e Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Wed, 21 Mar 2018 14:54:23 +0000 Subject: [PATCH] Added setVolume and setMute --- CHANGELOG.md | 2 ++ src/sound/html5/HTML5AudioSoundManager.js | 37 ++++++++++++++++++- src/sound/webaudio/WebAudioSoundManager.js | 41 ++++++++++++++++++++-- 3 files changed, 76 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7268f6075..f18746f73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,8 @@ A special mention must go to @orblazer for their outstanding assistance in helpi * Matter.SetBody and SetExistingBody will now set the origin of the Game Object to be the Matter JS sprite.xOffset and yOffset values, which will auto-center the Game Object to the origin of the body, regardless of shape. * SoundManager.setRate is a chainable method to allow you to set the global playback rate of all sounds in the SoundManager. * SoundManager.setDetune is a chainable method to allow you to set the global detuning of all sounds in the SoundManager. +* SoundManager.setMute is a chainable method to allow you to set the global mute state of the SoundManager. +* SoundManager.setVolume is a chainable method to allow you to set the global volume of the SoundManager. ### Bug Fixes diff --git a/src/sound/html5/HTML5AudioSoundManager.js b/src/sound/html5/HTML5AudioSoundManager.js index 5548fa670..700ce914b 100644 --- a/src/sound/html5/HTML5AudioSoundManager.js +++ b/src/sound/html5/HTML5AudioSoundManager.js @@ -150,7 +150,6 @@ var HTML5AudioSoundManager = new Class({ * devices on the initial explicit user interaction. * * @method Phaser.Sound.HTML5AudioSoundManager#unlock - * @private * @since 3.0.0 */ unlock: function () @@ -323,6 +322,24 @@ var HTML5AudioSoundManager = new Class({ * @param {boolean} value - An updated value of Phaser.Sound.HTML5AudioSoundManager#mute property. */ + /** + * Sets the muted state of all this Sound Manager. + * + * @method Phaser.Sound.HTML5AudioSoundManager#setMute + * @fires Phaser.Sound.HTML5AudioSoundManager#MuteEvent + * @since 3.3.0 + * + * @param {boolean} value - `true` to mute all sounds, `false` to unmute them. + * + * @return {Phaser.Sound.HTML5AudioSoundManager} This Sound Manager. + */ + setMute: function (value) + { + this.mute = value; + + return this; + }, + /** * @name Phaser.Sound.HTML5AudioSoundManager#mute * @type {boolean} @@ -356,6 +373,24 @@ var HTML5AudioSoundManager = new Class({ * @param {number} value - An updated value of Phaser.Sound.HTML5AudioSoundManager#volume property. */ + /** + * Sets the volume of this Sound Manager. + * + * @method Phaser.Sound.HTML5AudioSoundManager#setVolume + * @fires Phaser.Sound.HTML5AudioSoundManager#VolumeEvent + * @since 3.3.0 + * + * @param {number} value - The global volume of this Sound Manager. + * + * @return {Phaser.Sound.HTML5AudioSoundManager} This Sound Manager. + */ + setVolume: function (value) + { + this.volume = value; + + return this; + }, + /** * @name Phaser.Sound.HTML5AudioSoundManager#volume * @type {number} diff --git a/src/sound/webaudio/WebAudioSoundManager.js b/src/sound/webaudio/WebAudioSoundManager.js index ed36e9f50..3e0c43452 100644 --- a/src/sound/webaudio/WebAudioSoundManager.js +++ b/src/sound/webaudio/WebAudioSoundManager.js @@ -1,5 +1,6 @@ /** * @author Richard Davey + * @author Pavle Goloskokovic (http://prunegames.com) * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ @@ -16,7 +17,6 @@ var WebAudioSound = require('./WebAudioSound'); * @extends Phaser.Sound.BaseSoundManager * @memberOf Phaser.Sound * @constructor - * @author Pavle Goloskokovic (http://prunegames.com) * @since 3.0.0 * * @param {Phaser.Game} game - Reference to the current game instance. @@ -100,6 +100,7 @@ var WebAudioSoundManager = new Class({ if (audioConfig && audioConfig.context) { audioConfig.context.resume(); + return audioConfig.context; } @@ -119,7 +120,6 @@ var WebAudioSoundManager = new Class({ */ add: function (key, config) { - var sound = new WebAudioSound(this, key, config); this.sounds.push(sound); @@ -133,7 +133,6 @@ var WebAudioSoundManager = new Class({ * Read more about how this issue is handled here in [this article](https://medium.com/@pgoloskokovic/unlocking-web-audio-the-smarter-way-8858218c0e09). * * @method Phaser.Sound.WebAudioSoundManager#unlock - * @private * @since 3.0.0 */ unlock: function () @@ -215,6 +214,24 @@ var WebAudioSoundManager = new Class({ * @param {boolean} value - An updated value of Phaser.Sound.WebAudioSoundManager#mute property. */ + /** + * Sets the muted state of all this Sound Manager. + * + * @method Phaser.Sound.WebAudioSoundManager#setMute + * @fires Phaser.Sound.WebAudioSoundManager#MuteEvent + * @since 3.3.0 + * + * @param {boolean} value - `true` to mute all sounds, `false` to unmute them. + * + * @return {Phaser.Sound.WebAudioSoundManager} This Sound Manager. + */ + setMute: function (value) + { + this.mute = value; + + return this; + }, + /** * @name Phaser.Sound.WebAudioSoundManager#mute * @type {boolean} @@ -243,6 +260,24 @@ var WebAudioSoundManager = new Class({ * @param {number} value - An updated value of Phaser.Sound.WebAudioSoundManager#volume property. */ + /** + * Sets the volume of this Sound Manager. + * + * @method Phaser.Sound.WebAudioSoundManager#setVolume + * @fires Phaser.Sound.WebAudioSoundManager#VolumeEvent + * @since 3.3.0 + * + * @param {number} value - The global volume of this Sound Manager. + * + * @return {Phaser.Sound.WebAudioSoundManager} This Sound Manager. + */ + setVolume: function (value) + { + this.volume = value; + + return this; + }, + /** * @name Phaser.Sound.WebAudioSoundManager#volume * @type {number}