diff --git a/lime/utils/AssetLibrary.hx b/lime/utils/AssetLibrary.hx index 0c6ad5364..89db762ff 100644 --- a/lime/utils/AssetLibrary.hx +++ b/lime/utils/AssetLibrary.hx @@ -1,6 +1,7 @@ package lime.utils; +import haxe.io.Path; import lime.app.Event; import lime.app.Future; import lime.app.Promise; @@ -41,6 +42,10 @@ class AssetLibrary { private var promise:Promise; private var types = new Map (); + #if (js && html5) + private var pathGroups:Map>; + #end + public function new () { @@ -471,6 +476,41 @@ class AssetLibrary { public function loadAudioBuffer (id:String):Future { + // TODO: Better solution + + #if (js && html5) + if (pathGroups == null) { + + pathGroups = new Map> (); + + var sounds = new Map> (); + var type, path, soundName; + + for (id in types.keys ()) { + + type = types.get (id); + + if (type == MUSIC || type == SOUND) { + + path = paths.get (id); + soundName = Path.withoutExtension (path); + + if (!sounds.exists (soundName)) { + + sounds.set (soundName, new Array ()); + + } + + sounds.get (soundName).push (path); + pathGroups.set (id, sounds.get (soundName)); + + } + + } + + } + #end + if (cachedAudioBuffers.exists (id)) { return Future.withValue (cachedAudioBuffers.get (id)); @@ -481,7 +521,11 @@ class AssetLibrary { } else { + #if (js && html5) + return AudioBuffer.loadFromFiles (pathGroups.get (id)); + #else return AudioBuffer.loadFromFile (paths.get (id)); + #end }