phaser/v3/src/sound/WebAudioSoundManager.js
2017-11-15 14:38:45 +01:00

35 lines
1.1 KiB
JavaScript

var Class = require('../utils/Class');
var BaseSoundManager = require('./BaseSoundManager');
var WebAudioSound = require('./WebAudioSound');
// Phaser.Loader.WebAudioSoundManager
var WebAudioSoundManager = new Class({
Extends: BaseSoundManager,
initialize: function WebAudioSoundManager(game) {
BaseSoundManager.call(this, game);
/**
* The AudioContext being used for playback.
*
* @property {AudioContext} context
*/
this.context = this.createAudioContext();
/**
* [description]
*
* @property {GainNode} masterVolumeNode
*/
this.masterVolumeNode = this.context.createGain();
},
createAudioContext: function () {
var audioConfig = this.game.config.audio;
if (audioConfig && audioConfig.context) {
return audioConfig.context;
}
return new (window['AudioContext'] || window['webkitAudioContext'])();
},
add: function (key, config) {
var sound = new WebAudioSound(this, key, config);
this.sounds.push(sound);
return sound;
}
});
module.exports = WebAudioSoundManager;