I’m wondering how can i accomplish that with OpenFL 5.1.5 on desktop (Windows and Mac). Both Assets.getSound and Assets.loadSound expect a library id instead of a local path.
The use-case is:
I have some user-defined xml files which can have reference to audio files
These audio files are added by users to application folder (e.g. “exe_folder\assets\audio”)
Then when the program runs it should load the files declared in the xml
This fails with a null pointer error because Assets apparently only work with assets identified at compile time.
So, how can i dynamically load assets that aren’t part of the library? I know i can implement my own loader, but i thought openfl.Assets should have this functionality shouldn’t it?
You have to create your own loader to load bunch of files.
I have the same situation when I build casino game (lobby) where from I should load different games with different assets (graphics, audio).
In my case I create custom loader where I just loop through list of the files names and then call
@gonzos Thanks for the reply, but unfortunately that’s not my problem. As i mentioned, Assets.loadSound simply returns null in onComplete because the asset itself is only added to the folder after compilation and thus is not recognized as an embedded / included asset.
@singmajesty Thanks Josh, that looks like what i need! Is this asynchronous for all targets?
It appears that Sound.fromFile is synchronous (there is no loadFromFile method and it returns a Sound object instead of a loader).
Not a problem though - looks like the correct way to load audio asynchronously is to use lime.media.AudioBuffer.fromFile which returns a Future object, then in the onComplete method you can use Sound.fromAudioBuffer.