2017-11-10 11:55:32 +00:00
|
|
|
var Class = require('../utils/Class');
|
2017-11-10 12:05:29 +00:00
|
|
|
var BaseSoundManager = require('./BaseSoundManager');
|
2017-11-14 16:35:44 +00:00
|
|
|
var WebAudioSound = require('./WebAudioSound');
|
2017-11-10 12:05:29 +00:00
|
|
|
// Phaser.Loader.WebAudioSoundManager
|
2017-11-10 11:55:32 +00:00
|
|
|
var WebAudioSoundManager = new Class({
|
2017-11-10 12:05:29 +00:00
|
|
|
Extends: BaseSoundManager,
|
2017-11-14 15:49:01 +00:00
|
|
|
initialize: function WebAudioSoundManager(game) {
|
2017-11-14 16:35:44 +00:00
|
|
|
BaseSoundManager.call(this, game);
|
2017-11-10 11:55:32 +00:00
|
|
|
/**
|
2017-11-15 13:38:45 +00:00
|
|
|
* The AudioContext being used for playback.
|
|
|
|
*
|
|
|
|
* @property {AudioContext} context
|
2017-11-10 11:55:32 +00:00
|
|
|
*/
|
|
|
|
this.context = this.createAudioContext();
|
2017-11-15 13:38:45 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @property {GainNode} masterVolumeNode
|
|
|
|
*/
|
|
|
|
this.masterVolumeNode = this.context.createGain();
|
2017-11-10 11:55:32 +00:00
|
|
|
},
|
2017-11-14 15:49:01 +00:00
|
|
|
createAudioContext: function () {
|
2017-11-10 18:05:26 +00:00
|
|
|
var audioConfig = this.game.config.audio;
|
2017-11-14 15:49:01 +00:00
|
|
|
if (audioConfig && audioConfig.context) {
|
2017-11-10 18:05:26 +00:00
|
|
|
return audioConfig.context;
|
2017-11-10 11:55:32 +00:00
|
|
|
}
|
|
|
|
return new (window['AudioContext'] || window['webkitAudioContext'])();
|
2017-11-14 16:35:44 +00:00
|
|
|
},
|
|
|
|
add: function (key, config) {
|
|
|
|
var sound = new WebAudioSound(this, key, config);
|
|
|
|
this.sounds.push(sound);
|
|
|
|
return sound;
|
2017-11-10 11:55:32 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
module.exports = WebAudioSoundManager;
|