Loading sounds in the background?

Startup of apps may take up to 20 seconds on Android phones, since sound files have to be converted, and we have a lot of them.

I was thinking about loading them asynchronously in the background, using timers, but loadSound() does not have any events, so you could check onComplete and then load the next sound. You could start many timers loading sound effects with a fixed interval, but with the danger of overloading the system if it’s not timed correctly.

Also, I don’t know if sound conversion simply hangs everything, including the menu system?

What I would do is just load the sounds as quickly as possible while the user wallowed around in the menu system, and load the most important ones first. Worst case, some effects would not play in the beginning because they were not loaded yet.

Is there any technique to prevent holding the app back from starting because of all the sound conversion going on?

Have you considered using audio.loadStream()? 

loadStream() is for long sounds like background music, right? My sounds are all short sound effects, it’s just many of them. Anyway, please answer if there is any way to do sound conversion in the background (the object being to eliminate blocking sound conversion code in the startup process), which was my original request.

Hi @olavm,

What kind of sound format are you using? .ogg? .wav?

Brent

I use mp3. WAV would take way too much space (it would double the app size).

Rob Miracle said earlier this winter there was really no point in trying to use different formats for Android, because no matter which formats you use, they will be slow on some Androids and quick on others.

Let me know if this is wrong, or if there’s another solution of avoiding blocking sound conversion code.

We have 60 sound effects in mp3 totaling 1.5 MB. Each sound effect is between 4 KB and 100 KB (average 25KB).

Hi olavm,

Yes, tosome degree, the sounds will just load slower on some phones as they decode. Out of curiosity though, have you tried loading and playing them via the “media” library methods?

http://docs.coronalabs.com/api/library/media/newEventSound.html

Brent

Right, while loadStream is intended for longer tracks, it doesn’t block.  It starts decoding right away.  This might help loading.

What can help too is keeping the file size small.  44Khz stereo tracks are big and take time to read in.  11khz mono tracks load a lot faster.  There of course is still the decode time which is very dependent on hardware and software (OS/Drivers, etc) loaded on the device.

I guess it seems pretty inevitable that it will take a little while to load the sound files due to the number of files that you have. This doesn’t directly answer your question, however, It might be worth enhancing the user’s experience by adding in a loading page where progress of the loading bar corresponds to the progression in loading up these sounds (and any other resources).  This can be done using coroutines.  There will be examples on the web for doing this.

Have you considered using audio.loadStream()? 

loadStream() is for long sounds like background music, right? My sounds are all short sound effects, it’s just many of them. Anyway, please answer if there is any way to do sound conversion in the background (the object being to eliminate blocking sound conversion code in the startup process), which was my original request.

Hi @olavm,

What kind of sound format are you using? .ogg? .wav?

Brent

I use mp3. WAV would take way too much space (it would double the app size).

Rob Miracle said earlier this winter there was really no point in trying to use different formats for Android, because no matter which formats you use, they will be slow on some Androids and quick on others.

Let me know if this is wrong, or if there’s another solution of avoiding blocking sound conversion code.

We have 60 sound effects in mp3 totaling 1.5 MB. Each sound effect is between 4 KB and 100 KB (average 25KB).

Hi olavm,

Yes, tosome degree, the sounds will just load slower on some phones as they decode. Out of curiosity though, have you tried loading and playing them via the “media” library methods?

http://docs.coronalabs.com/api/library/media/newEventSound.html

Brent

Right, while loadStream is intended for longer tracks, it doesn’t block.  It starts decoding right away.  This might help loading.

What can help too is keeping the file size small.  44Khz stereo tracks are big and take time to read in.  11khz mono tracks load a lot faster.  There of course is still the decode time which is very dependent on hardware and software (OS/Drivers, etc) loaded on the device.

I guess it seems pretty inevitable that it will take a little while to load the sound files due to the number of files that you have. This doesn’t directly answer your question, however, It might be worth enhancing the user’s experience by adding in a loading page where progress of the loading bar corresponds to the progression in loading up these sounds (and any other resources).  This can be done using coroutines.  There will be examples on the web for doing this.