Skip to content

Commit 2ad39a9

Browse files
added play method to WebAudioSound class
1 parent 57c602d commit 2ad39a9

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

v3/src/sound/WebAudioSound.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var Class = require('../utils/Class');
22
var BaseSound = require('./BaseSound');
3+
var Extend = require('../utils/object/Extend');
34
// Phaser.Sound.WebAudioSound
45
var WebAudioSound = new Class({
56
Extends: BaseSound,
@@ -16,6 +17,27 @@ var WebAudioSound = new Class({
1617
}
1718
config.duration = this.audioBuffer.duration;
1819
BaseSound.call(this, manager, key, config);
20+
},
21+
play: function (marker, config) {
22+
if (marker === void 0) { marker = ''; }
23+
if (typeof marker !== 'string') {
24+
console.error('Sound marker has to be a string!');
25+
return;
26+
}
27+
if (config) {
28+
if (!marker) {
29+
this.config = Extend(this.config, config);
30+
}
31+
else {
32+
this.markers[marker].config = Extend(this.markers[marker].config, config);
33+
}
34+
}
35+
var source = this.manager.context.createBufferSource();
36+
// TODO assign config values to buffer source
37+
source.buffer = this.audioBuffer;
38+
source.connect(this.manager.context.destination);
39+
source.start();
40+
return this;
1941
}
2042
});
2143
module.exports = WebAudioSound;

0 commit comments

Comments
 (0)