Skip to content

Commit 8c0eaf3

Browse files
added AudioFile constructor
loading AudioFile if Web Audio is enabled added a couple of todos changed return value of findAudioURL method to expose extension if available
1 parent 13b5440 commit 8c0eaf3

1 file changed

Lines changed: 28 additions & 9 deletions

File tree

v3/src/loader/filetypes/AudioFile.js

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,30 @@ var GetFastValue = require('../../utils/object/GetFastValue');
77

88
var AudioFile = new Class({
99

10-
Extends: File
10+
Extends: File,
11+
12+
initialize:
13+
14+
function AudioFile (key, url, path, xhrSettings)
15+
{
16+
var fileConfig = {
17+
type: 'audio',
18+
extension: GetFastValue(url, 'type', ''),
19+
responseType: 'arraybuffer',
20+
key: key,
21+
url: GetFastValue(url, 'uri', url),
22+
path: path,
23+
xhrSettings: xhrSettings
24+
};
25+
26+
File.call(this, fileConfig);
27+
}
1128

1229
});
1330

1431
AudioFile.create = function (loader, key, urls, config, xhrSettings)
1532
{
33+
// TODO handle when sounds are disabled in game config
1634

1735
var url = AudioFile.findAudioURL(urls);
1836

@@ -24,18 +42,17 @@ AudioFile.create = function (loader, key, urls, config, xhrSettings)
2442

2543
if (Audio.webAudio)
2644
{
27-
45+
loader.addFile(new AudioFile(key, url, loader.path, xhrSettings));
2846
}
2947
else if (Audio.audioData)
3048
{
31-
49+
// TODO handle loading audio tags
3250
}
3351
else
3452
{
3553
// TODO bail if sounds are disabled and print message
3654
return;
3755
}
38-
3956
};
4057

4158
// this.load.audio('sound', 'assets/audio/booom.ogg', config, xhrSettings);
@@ -97,13 +114,15 @@ AudioFile.findAudioURL = function (urls)
97114
return url;
98115
}
99116

100-
var audioType = url.match(/\.([a-zA-Z0-9]+)($|\?)/);
117+
var type = url.match(/\.([a-zA-Z0-9]+)($|\?)/);
118+
type = GetFastValue(urls[i], 'type', type ? type[1] : '').toLowerCase();
101119

102-
audioType = GetFastValue(urls[i], 'type', audioType ? audioType[1] : '').toLowerCase();
103-
104-
if (Audio[audioType])
120+
if (Audio[type])
105121
{
106-
return url;
122+
return {
123+
uri: url,
124+
type: type
125+
};
107126
}
108127
}
109128

0 commit comments

Comments
 (0)