phaser/v3/src/sound/WebAudioSoundManager.js

36 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-11-10 11:55:32 +00:00
var Class = require('../utils/Class');
var BaseSoundManager = require('./BaseSoundManager');
var WebAudioSound = require('./WebAudioSound');
// Phaser.Loader.WebAudioSoundManager
2017-11-10 11:55:32 +00:00
var WebAudioSoundManager = new Class({
Extends: BaseSoundManager,
initialize: function WebAudioSoundManager(game) {
BaseSoundManager.call(this, game);
2017-11-10 11:55:32 +00:00
/**
* The AudioContext being used for playback.
*
* @property {AudioContext} context
2017-11-10 11:55:32 +00:00
*/
this.context = this.createAudioContext();
/**
* [description]
*
* @property {GainNode} masterVolumeNode
*/
this.masterVolumeNode = this.context.createGain();
2017-11-10 11:55:32 +00:00
},
createAudioContext: function () {
var audioConfig = this.game.config.audio;
if (audioConfig && audioConfig.context) {
return audioConfig.context;
2017-11-10 11:55:32 +00:00
}
return new (window['AudioContext'] || window['webkitAudioContext'])();
},
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;