mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 21:53:59 +00:00
Docs for Sound Managers
This commit is contained in:
parent
88b088b6a2
commit
677cfae424
4 changed files with 26 additions and 21 deletions
|
@ -14,12 +14,7 @@ var NOOP = require('../utils/NOOP');
|
|||
|
||||
/**
|
||||
* @classdesc
|
||||
* The sound manager is responsible for playing back audio via Web Audio API or HTML Audio tag as fallback.
|
||||
* The audio file type and the encoding of those files are extremely important.
|
||||
*
|
||||
* Not all browsers can play all audio formats.
|
||||
*
|
||||
* There is a good guide to what's supported [here](https://developer.mozilla.org/en-US/Apps/Fundamentals/Audio_and_video_delivery/Cross-browser_audio_basics#Audio_Codec_Support).
|
||||
* Base class for other Sound Manager classes.
|
||||
*
|
||||
* @class BaseSoundManager
|
||||
* @extends Phaser.Events.EventEmitter
|
||||
|
@ -28,6 +23,10 @@ var NOOP = require('../utils/NOOP');
|
|||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Game} game - Reference to the current game instance.
|
||||
*
|
||||
* @see Phaser.Sound.HTML5AudioSoundManager
|
||||
* @see Phaser.Sound.NoAudioSoundManager
|
||||
* @see Phaser.Sound.WebAudioSoundManager
|
||||
*/
|
||||
var BaseSoundManager = new Class({
|
||||
|
||||
|
|
|
@ -12,16 +12,19 @@ var HTML5AudioSound = require('./HTML5AudioSound');
|
|||
|
||||
/**
|
||||
* HTML5 Audio implementation of the Sound Manager.
|
||||
*
|
||||
* Note: To play multiple instances of the same HTML5 Audio sound, you need to provide an `instances` value when
|
||||
*
|
||||
* To play multiple instances of the same HTML5 Audio sound, you need to provide an `instances` value when
|
||||
* loading the sound with the Loader:
|
||||
*
|
||||
*
|
||||
* ```javascript
|
||||
* this.load.audio('explosion', 'explosion.mp3', {
|
||||
* instances: 2
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* Not all browsers can play all audio formats.
|
||||
* There is a good guide to what's supported: [Cross-browser audio basics: Audio codec support](https://developer.mozilla.org/en-US/Apps/Fundamentals/Audio_and_video_delivery/Cross-browser_audio_basics#Audio_Codec_Support).
|
||||
*
|
||||
* @class HTML5AudioSoundManager
|
||||
* @extends Phaser.Sound.BaseSoundManager
|
||||
* @memberof Phaser.Sound
|
||||
|
|
|
@ -13,10 +13,10 @@ var NOOP = require('../../utils/NOOP');
|
|||
|
||||
/**
|
||||
* @classdesc
|
||||
* No audio implementation of the sound manager. It is used if audio has been
|
||||
* No-audio implementation of the Sound Manager. It is used if audio has been
|
||||
* disabled in the game config or the device doesn't support any audio.
|
||||
*
|
||||
* It represents a graceful degradation of sound manager logic that provides
|
||||
* It represents a graceful degradation of Sound Manager logic that provides
|
||||
* minimal functionality and prevents Phaser projects that use audio from
|
||||
* breaking on devices that don't support any audio playback technologies.
|
||||
*
|
||||
|
|
|
@ -13,7 +13,10 @@ var WebAudioSound = require('./WebAudioSound');
|
|||
|
||||
/**
|
||||
* @classdesc
|
||||
* Web Audio API implementation of the sound manager.
|
||||
* Web Audio API implementation of the Sound Manager.
|
||||
*
|
||||
* Not all browsers can play all audio formats.
|
||||
* There is a good guide to what's supported: [Cross-browser audio basics: Audio codec support](https://developer.mozilla.org/en-US/Apps/Fundamentals/Audio_and_video_delivery/Cross-browser_audio_basics#Audio_Codec_Support).
|
||||
*
|
||||
* @class WebAudioSoundManager
|
||||
* @extends Phaser.Sound.BaseSoundManager
|
||||
|
@ -117,7 +120,7 @@ var WebAudioSoundManager = new Class({
|
|||
/**
|
||||
* This method takes a new AudioContext reference and then sets
|
||||
* this Sound Manager to use that context for all playback.
|
||||
*
|
||||
*
|
||||
* As part of this call it also disconnects the master mute and volume
|
||||
* nodes and then re-creates them on the new given context.
|
||||
*
|
||||
|
@ -180,16 +183,16 @@ var WebAudioSoundManager = new Class({
|
|||
|
||||
/**
|
||||
* Decode audio data into a format ready for playback via Web Audio.
|
||||
*
|
||||
*
|
||||
* The audio data can be a base64 encoded string, an audio media-type data uri, or an ArrayBuffer instance.
|
||||
*
|
||||
*
|
||||
* The `audioKey` is the key that will be used to save the decoded audio to the audio cache.
|
||||
*
|
||||
*
|
||||
* Instead of passing a single entry you can instead pass an array of `Phaser.Types.Sound.DecodeAudioConfig`
|
||||
* objects as the first and only argument.
|
||||
*
|
||||
*
|
||||
* Decoding is an async process, so be sure to listen for the events to know when decoding has completed.
|
||||
*
|
||||
*
|
||||
* Once the audio has decoded it can be added to the Sound Manager or played via its key.
|
||||
*
|
||||
* @method Phaser.Sound.WebAudioSoundManager#decodeAudio
|
||||
|
@ -231,7 +234,7 @@ var WebAudioSoundManager = new Class({
|
|||
var success = function (key, audioBuffer)
|
||||
{
|
||||
cache.add(key, audioBuffer);
|
||||
|
||||
|
||||
this.emit(Events.DECODED, key);
|
||||
|
||||
remaining--;
|
||||
|
@ -241,7 +244,7 @@ var WebAudioSoundManager = new Class({
|
|||
this.emit(Events.DECODED_ALL);
|
||||
}
|
||||
}.bind(this, key);
|
||||
|
||||
|
||||
var failure = function (key, error)
|
||||
{
|
||||
// eslint-disable-next-line no-console
|
||||
|
@ -283,7 +286,7 @@ var WebAudioSoundManager = new Class({
|
|||
body.removeEventListener('touchend', unlockHandler);
|
||||
body.removeEventListener('click', unlockHandler);
|
||||
body.removeEventListener('keydown', unlockHandler);
|
||||
|
||||
|
||||
_this.unlocked = true;
|
||||
}, function ()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue