diff --git a/lime/utils/AssetLibrary.hx b/lime/utils/AssetLibrary.hx index 6d7ba11d1..8cd6c58bf 100644 --- a/lime/utils/AssetLibrary.hx +++ b/lime/utils/AssetLibrary.hx @@ -453,41 +453,6 @@ 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)); @@ -499,11 +464,15 @@ class AssetLibrary { } else { #if (js && html5) - return AudioBuffer.loadFromFiles (pathGroups.get (id)); - #else - return AudioBuffer.loadFromFile (paths.get (id)); + if (pathGroups.exists (id)) { + + return AudioBuffer.loadFromFiles (pathGroups.get (id)); + + } #end + return AudioBuffer.loadFromFile (paths.get (id)); + } } @@ -679,6 +648,57 @@ class AssetLibrary { } + // TODO: Better solution + + #if (js && html5) + if (pathGroups == null) { + + pathGroups = new Map> (); + + } + + var sounds = new Map> (); + var preloadGroups = 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)); + + if (preload.exists (id)) { + + if (preloadGroups.exists (soundName)) { + + preload.remove (id); + + } else { + + preloadGroups.set (soundName, true); + + } + + } + + } + + } + #end + + }