Android NDK createSound error

My game runs on Android using the native app glue so it’s pure C++. I have a very simple java activity that loads fmod:

import android.app.NativeActivity;

public class MainActivity extends NativeActivity 
{
 static
 {
   System.loadLibrary("fmodL");
 }
}

Then on the C++ side, my sound engine inits like this (and works fine):

  System* pSystem = NULL;
  FMOD_RESULT r = System_Create(&pSystem);
  if (r != FMOD_OK)
  {
    GP_ERROR("Unable to start FMOD. Error Code: %d", r);
  }

  r = pSystem->init(128, FMOD_INIT_NORMAL, NULL);
  if (r != FMOD_OK)
  {
    GP_ERROR("Unable to init FMOD. Error Code: %d", r);
  }

However, it seems any attempt to create a sound, none of the attempts below work in that createSound returns FMOD_ERR_FILE_NOTFOUND.

  Sound* pSound = NULL;

  pSystem->createSound("file:///android_asset/res/audio/effects/testSound.wav", FMOD_DEFAULT, NULL, &pSound);

  pSystem->createSound("res/audio/effects/testSound.wav", FMOD_DEFAULT, NULL, &pSound);

Is there something I’ve missed?

For FMOD to be able to read from the asset manager it needs to be initialized with your activity. You can do this by calling FMODAudioDevice.init(activity) from your minimal Java wrapper.

Once initialized you will be able to use the file:///android_asset syntax to load files from your APK. Without the asset manager you must load unpacked files from external storage.

1 Like