void myFunc(){
auto* env = JniHelper::getEnv();
cocos2d::JniMethodInfo methodInfo;
// I have tried with all three signatures, none of which worked
if (! JniHelper::getStaticMethodInfo(
methodInfo,
"org/cocos2dx/cpp/AppActivity",
"getIn",
//"()Lorg/cocos2dx/cpp/AppActivity"))
"()Landroid/app/Activity"))
//"()Ljava/lang/Object"))
{
// this segment is executed each time, meaning it failed
MXLOG_R("Error: Could not invoke Java method");
_ckEngineFailed = true;
return;
}
jobject activity = methodInfo.env->CallStaticObjectMethod(methodInfo.classID, methodInfo.methodID);
CkConfig config(env, activity); // I need the activity instance to initialize Cricket Audio
methodInfo.env->DeleteLocalRef(methodInfo.classID);
methodInfo.env->DeleteLocalRef(activity);
}
Thank you for posting your solutions! However I’ve gotten my version working too. The semicolon (" ; ") is mandatory for the signature, it looks like! When I tried the following:
, now with the semicolon present, it worked (or at least for what I know the JNI call returns 1 instead of 0)! This seems very stupid design to me, but well this is it, keep writing the semicolons even if there is no list present!
(The code that followed the obtainment of the Activity instance still failed however, that needs further debugging)
If someone is interested in how to initialize the Cricket engine, you have to keep the activity reference alive until the CkInit(&config) function finishes. Now everything works fine. And by the way, if you use Cocos’ default audio engine (either the old or the new), you are doing it wrong It has insane performance issues and a wide variety of bugs on most platforms. This is the alternative: http://www.crickettechnology.com
Is it good one? Have you tested it already? we also were looking for new audio engine for cocos2d-x. Btw how to make music bank - do they have some software for it or it is some other softare which can be used with? Is loop music works without delay on Android devices?
On my Galaxy S7, using experimental::AudioEngine, playing a couple of short .ogg sounds every 256ms caused me -20 fps (!) and it didn’t even play half the sounds and their volumes were jumping around. With Cricket I haven’t noticed any fps drops and everything is as loud as I want it to be, plus it’s api has much more features.
You list the files you want to put into your bank file in an xml file, then use the cktool that they provided with the rest of the engine. Easiest is to add the path of that cktool binary to your PATH variable (if u’re on windows) then go to where your .wav/.aiff and xml files are and do “cktool buildbank mybankxmlfile.ckbx mybank.ckb”.
Additionally, I think the easiest way to use the bank sounds then in your program is to initialize your bank AND your bank sounds at start of your program, and don’t destroy them at all (unless there’s sounds you really don’t want to use later in your program). I have a sound lookup where I store the CkSound pointers, whenever I want to play a sound I get a pointer to it and do sound->play()… that’s it. Setting the default volumes and such can be done at the step where you put them in your bank file but I just set all default settings at the time I initialize them. This way I can utilize procedural c++ tools instead of editing xml files.
Hi, can you please check my post I tagged u there. We now trying Cricket engine and so far don’t like that we should use wav files to make it work and it’s not streaming sounds by some reason when bank is not used.
Do you have any code snippet to do this for the Cricket config call? I have been using Cricket with Cocos2dx on Win32 and iOS, but haven’t been able to figure this part out for Android. Thanks!