Skip to content

Commit 73aa864

Browse files
added WebAudioSoundManager class
1 parent a76a653 commit 73aa864

3 files changed

Lines changed: 41 additions & 9 deletions

File tree

v3/src/sound/SoundManager.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
var Class = require('../utils/Class');
2+
var WebAudioSoundManager = require('./WebAudioSoundManager');
23

34
// Phaser.Loader.SoundManager
45

56
var SoundManager = new Class({
67

7-
initialize:
8-
9-
function SoundManager (game)
10-
{
11-
12-
}
8+
// TODO define sound manager interface
139

1410
});
1511

@@ -24,8 +20,7 @@ SoundManager.create = function (game)
2420
if(game.device.Audio.webAudio
2521
&& !(game.config.audio && game.config.audio.disableWebAudio))
2622
{
27-
// TODO create Web Audio sound manager
28-
return new SoundManager(game);
23+
return new WebAudioSoundManager(game);
2924
}
3025

3126
// TODO return HTML5 Audio sound manager
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
var Class = require('../utils/Class');
2+
var SoundManager = require('./SoundManager');
3+
4+
var WebAudioSoundManager = new Class({
5+
6+
Extends: SoundManager,
7+
8+
initialize:
9+
10+
function WebAudioSoundManager (game)
11+
{
12+
/**
13+
* @property {Phaser.Game} game - Local reference to game.
14+
*/
15+
this.game = game;
16+
17+
/**
18+
* @property {AudioContext} context - The AudioContext being used for playback.
19+
* @default
20+
*/
21+
this.context = this.createAudioContext();
22+
},
23+
24+
createAudioContext: function ()
25+
{
26+
if (this.game.config.audio.context)
27+
{
28+
return this.game.config.audio.context;
29+
}
30+
31+
return new (window['AudioContext'] || window['webkitAudioContext'])();
32+
}
33+
34+
});
35+
36+
module.exports = WebAudioSoundManager;

v3/src/sound/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = {
44

55
Dynamic: require('./dynamic'),
66

7-
SoundManager: require('./SoundManager')
7+
SoundManager: require('./SoundManager'),
8+
WebAudioSoundManager: require('./WebAudioSoundManager')
89

910
};

0 commit comments

Comments
 (0)