mirror of
https://github.com/photonstorm/phaser
synced 2024-12-28 05:53:49 +00:00
35 lines
1.1 KiB
JavaScript
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;
|