2017-11-14 15:27:22 +00:00
|
|
|
var Class = require('../utils/Class');
|
|
|
|
var BaseSound = require('./BaseSound');
|
2017-11-14 18:35:18 +00:00
|
|
|
var Extend = require('../utils/object/Extend');
|
2017-11-14 15:27:22 +00:00
|
|
|
// Phaser.Sound.WebAudioSound
|
|
|
|
var WebAudioSound = new Class({
|
|
|
|
Extends: BaseSound,
|
|
|
|
initialize: function WebAudioSound(manager, key, config) {
|
2017-11-14 18:30:51 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @property {AudioBuffer} audioBuffer
|
|
|
|
*/
|
|
|
|
this.audioBuffer = this.manager.game.cache.audio.get(key);
|
|
|
|
if (!this.audioBuffer) {
|
|
|
|
console.error('No audio loaded in cache with key: \'' + key + '\'!');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
config.duration = this.audioBuffer.duration;
|
2017-11-14 15:27:22 +00:00
|
|
|
BaseSound.call(this, manager, key, config);
|
2017-11-14 18:35:18 +00:00
|
|
|
},
|
|
|
|
play: function (marker, config) {
|
|
|
|
if (marker === void 0) { marker = ''; }
|
|
|
|
if (typeof marker !== 'string') {
|
|
|
|
console.error('Sound marker has to be a string!');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (config) {
|
|
|
|
if (!marker) {
|
|
|
|
this.config = Extend(this.config, config);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.markers[marker].config = Extend(this.markers[marker].config, config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var source = this.manager.context.createBufferSource();
|
|
|
|
// TODO assign config values to buffer source
|
|
|
|
source.buffer = this.audioBuffer;
|
|
|
|
source.connect(this.manager.context.destination);
|
|
|
|
source.start();
|
|
|
|
return this;
|
2017-11-14 15:27:22 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
module.exports = WebAudioSound;
|