Here I will show you how to import audio files at runtime using the Runtime Audio Importer plugin.
First, you need to create a Runtime Audio Importer object. This can be done using the "Create Runtime Audio Importer" function.
If you want to know the percentage of the audio file import process (for example, to implement a loading screen), then you need to bind to the "OnProgress" delegate, which is available in the created Runtime Audio Importer object.
To know when the import process is complete, as well as to get the SoundWave object, you need to bind to the "OnResult" delegate, which is available in the created Runtime Audio Importer object.
To start the import process, call the "Import Audio From File" or "Import Audio From Buffer" function. You should fill a "File Path" and "Format" properties, which are described here.
After the import is finished, you will receive the required SoundWave from the "OnResult" delegate described above.
Now I will briefly write the whole import process.
1. Create Runtime Audio Importer. Each time you want to import an audio file, you need to create a separate instance of the Runtime Audio Importer object. Otherwise, there may be problems with leaks and memory access.
2. Bind to all required delegates. It can be OnProgress and OnResult.
3. Import audio from file or buffer.
4. Play the imported sound wave received through the OnResult delegate.
Important! If you want to stop playing a sound wave and clear its data, before clearing the data through Release Memory (more details on this page), you should process a small Delay for about half a second. This is necessary due to the fact that after stopping the playback of the sound wave, the engine can use the residual data of the audio buffer or request a new one, and therefore a Memory Access Violation error is possible due to the fact that the data has been cleared by the Release Memory function.
You can also import uncompressed RAW audio formats (in case you don't have a header). To do this, instead of "Import Audio From File" or "Import Audio From Buffer" use "Import Audio From RAW File" or "Import Audio From RAW Buffer"