Search code examples
objective-ciosfmod

iOS - Multiple apps using FMOD - audio only works in the first app to be run


I'm working on an existing app that I did not develop, and it plays its audio using FMOD.

From the looks of things, previous versions of the app were written to use AVAudioPlayer instead, and there are build options to use either.

The most recent versions use FMOD though, because a lot of the functionality is only included when built using the FMOD version.

The problem comes when I use one of the existing apps first, then try to run this new one that I'm developing.

If I run one app, then leave it in the background and run the second app, the sound in the second app doesn't play at all. I can go back to the first app and play sound without problems. If I kill both apps, and start the other one first, then it works perfectly.

If I build the app using the AVAudioPlayer option, then I don't get this problem, but also all of the functionality that was written for the FMOD version is not there. I can therefore prove that it is something to do with FMOD, but can't figure out what.

EDIT: Have done a little more digging, and I'm getting two FMOD errors:

Firstly, when I run:
result = fmodSystem->init(4, FMOD_INIT_NORMAL | FMOD_INIT_ENABLE_PROFILE, NULL);
I get error 51 - "A socket error occurred. This is a catch-all for socket-related errors not listed elsewhere."

Secondly, when I run:
result = fmodSystem->createSound((const char *)[audioData bytes], FMOD_SOFTWARE | FMOD_OPENMEMORY, &exinfo, &fmodSound);
I get error 79 - "This command failed because System::init or System::setDriver was not called."

The second seems to be because the init failed.


Solution

  • This was answered via Twitter, therefore I'll put the answer here myself, however, if Stuart would like to answer it himself here, then I'll vote that as the answer.

    The answer is to disable: FMOD_INIT_ENABLE_PROFILE, because that can only run in one app at a time:

    Therefore, this:
    result = fmodSystem->init(4, FMOD_INIT_NORMAL | FMOD_INIT_ENABLE_PROFILE, NULL);

    Should become this:
    result = fmodSystem->init(4, FMOD_INIT_NORMAL, NULL);