Issue with wav files and building for Android

I got enterprise set up for Android today but I have this issue where it has problems loading audio only on the device.  Error message is here:

WARNING: audio.loadSound() failed to create sound ‘Resource/Sounds/Keypads/1/1.wav’

There are 12 files in total (named 1-12.wav) and they all error out.

If I do a non enterprise build this does not happen and the audio works fine on the device.  

If I move the wav files into Resource/Sounds and build with enterprise then we are also good.  If I move the wav file to Resource/Sounds/Keypads and build with enterprise then I get the error.  

Mp3 files structured in a similar way also load up OK.

So I wondered if I have missed something, is there anything I need to do when building with enterprise to make the audio api work the same as a non enterprise build?

Corona’s Lua “system.ResourceDirectory” references your Android app’s “assets” directory, not it’s “res” directory.  So, your audio files need to be in the assets directory.

If you look at our Corona Enterprise sample projects, notice that we have a pre-build step that it copies files from a “corona” directory (that’s your Corona project directory) to your android app project’s “assets” directory.  You’ll want to set up your project like that.

Thanks for the quick reply but I’m a little confused!  So the “Resource” directory I mention is in system.ResourceDirectory/the “Corona” directory so it would be system.ResourceDirectory/Resource/Sounds…  if that makes sense?  All the other mp3 files located within this structure work properly just not the wavs?

When you are building with Corona Enterprise, notice that you have an “android” directory and a “corona” directory right next to each other.  You should copy all of your Corona project files (Lua scripts, audio files, image files, etc.) to the “corona” directory.  When you build your Android project via our “build.sh” script, it’ll copy all of your assets from your “corona” directory to the Android project’s “assets” directory (except for the scripts which get compiled and archived into a “resource.car” file into the “assets” directory).

As a quick test, try copying our “AudioPlayer” sample project that is included with the Corona Simulator to one of our Corona Enterprise sample project’s “corona” directories and build it as is.

That’s exactly how I have it set up though? Guess I’ll try the audio player sample as a comparison then.

I suggest that you start by compiling a Corona Enterprise sample project as-is, without modification, to verify that your build environment is set up correctly.  Such as the “LaunchingFromNativeUI” sample.  That particular sample project includes images and wav files.

Joshua thanks for the help!  I built the sample and all was well with that even when I moved the wav file several directories away from the root.  

I then went back to my original project and checked out the “assets” folder you mentioned.  Sure enough the problem hit me, previously the audio load error was caused by the folder name being named “keypads” instead of “Keypads” (lower case k).  I updated it in the Corona directory so I assumed it would update in the assets folder too when I ran the build script.  But I guess not, I assume it must do some more of a sync than clearing out the folder and replacing the contents.  

I also checked in the sample project I was messing with too and various versions of folder structures I was trying are also still in the “assets” folder.   

From now on when I am messing about with the project structure in the Corona folder I will make sure to delete the assets folder so nothing gets mixed up.

Ahh yes.  The Android files system is indeed case sensitive.  And I think the Mac OS file system handles renames oddly too (or is it my imagination?).  Did you have to delete your subdirectory and re-create with the correct casing to get it to work as well?

So to summarise I changed:

“Project/Corona/Resource/Sounds/keypads” to “Project/Corona/Resource/Sounds/Keypads” but after running the build script “Project/android/assets/Resource/Sounds/keypads” remained lower case.  I deleted the whole “assets” folder, ran the script again and it was OK after that.

As I mentioned though I also noticed files I had moved previously, had not had their old locations deleted.  So for example I had something like:

Project/Corona/Resource/Sounds/myWavFile.wav

Then moved it to:

Project/Corona/Resource/Sounds/Keypads/myWavFile.wav

In assets, the file appeared in both those locations which is why I mentioned that it obviously doesn’t strip out its contents before copying new stuff in.

Yeah, that would make sense.  Since the Mac file system is not case sensitive by default, it ended up copying your Corona project’s “Keypads” folder to your Android assets “keypads” folder, since that was the original name.  It doesn’t know to rename the folder to change the casing.  Windows would have done the same.  Thanks for bringing this up.  I’ll have to remember in case someone else runs into something similar.

Does it not make more sense for the build script to delete the contents of the android/assets folder altogether though when it is run to avoid stuff like this?

>> Does it not make more sense for the build script to delete the contents of the android/assets folder altogether

I personally wouldn’t like that because it would assume that the native Android developer is *only* using Corona.  With the way it’s set up now, it respects whatever files the native Android developer copied to the assets directory because they may be using them for their own purposes outside of Corona.  Plus, most experienced native Android developers wouldn’t expect a prebuild step to outright delete that folder.

Yeah fair enough i suppose, I was looking at it from the point of developing using corona as the primary tool.

Corona’s Lua “system.ResourceDirectory” references your Android app’s “assets” directory, not it’s “res” directory.  So, your audio files need to be in the assets directory.

If you look at our Corona Enterprise sample projects, notice that we have a pre-build step that it copies files from a “corona” directory (that’s your Corona project directory) to your android app project’s “assets” directory.  You’ll want to set up your project like that.

Thanks for the quick reply but I’m a little confused!  So the “Resource” directory I mention is in system.ResourceDirectory/the “Corona” directory so it would be system.ResourceDirectory/Resource/Sounds…  if that makes sense?  All the other mp3 files located within this structure work properly just not the wavs?

When you are building with Corona Enterprise, notice that you have an “android” directory and a “corona” directory right next to each other.  You should copy all of your Corona project files (Lua scripts, audio files, image files, etc.) to the “corona” directory.  When you build your Android project via our “build.sh” script, it’ll copy all of your assets from your “corona” directory to the Android project’s “assets” directory (except for the scripts which get compiled and archived into a “resource.car” file into the “assets” directory).

As a quick test, try copying our “AudioPlayer” sample project that is included with the Corona Simulator to one of our Corona Enterprise sample project’s “corona” directories and build it as is.

That’s exactly how I have it set up though? Guess I’ll try the audio player sample as a comparison then.

I suggest that you start by compiling a Corona Enterprise sample project as-is, without modification, to verify that your build environment is set up correctly.  Such as the “LaunchingFromNativeUI” sample.  That particular sample project includes images and wav files.

Joshua thanks for the help!  I built the sample and all was well with that even when I moved the wav file several directories away from the root.  

I then went back to my original project and checked out the “assets” folder you mentioned.  Sure enough the problem hit me, previously the audio load error was caused by the folder name being named “keypads” instead of “Keypads” (lower case k).  I updated it in the Corona directory so I assumed it would update in the assets folder too when I ran the build script.  But I guess not, I assume it must do some more of a sync than clearing out the folder and replacing the contents.  

I also checked in the sample project I was messing with too and various versions of folder structures I was trying are also still in the “assets” folder.   

From now on when I am messing about with the project structure in the Corona folder I will make sure to delete the assets folder so nothing gets mixed up.

Ahh yes.  The Android files system is indeed case sensitive.  And I think the Mac OS file system handles renames oddly too (or is it my imagination?).  Did you have to delete your subdirectory and re-create with the correct casing to get it to work as well?