I’m trying to test the AudioDeviceManager in Android but i cant make it to successfully call initialise or initialiseWithDefaultDevice(), here’s my code:
You are not creating the AudioDeviceManager you are attempting to use.
You need to do something like :
static std::unique_ptr<AudioDeviceManager> deviceManager;
JNIEXPORT void JNICALL
Java_com_solace_sol_MainActivityKt_playAudio(JNIEnv *env, jclass clazz, jstring filePath) {
if (!deviceManager) // is the devicemanager a null pointer?
{
deviceManager = std::make_unique<juce::AudioDeviceManager>(); // if yes, then create and init the manager instance
String err = deviceManager->initialiseWithDefaultDevices(0, 2);
Log::e(err.toStdString().c_str());
}
}
}
This would lead to a memory leak, though. You’d need another function exported to your Android side that cleans up your C++ object(s) after they are not needed anymore.
Maybe something like (I am not familiar with the Android interoperation, so the syntax for the function declaration might not be right) :