System::mixerResume() crash on Android using Native Activity.
All is fine using Java activity. The problem is only with Native Activity.
The first call to mixerResume make the last few milliseconds of sound repeat forever and the second call to mixerResume crashes the app.
The error code is always OK and the logcat shows nothing suspicious.
I call mixerSuspend on APP_CMD_STOP command and mixerResume on APP_CMD_START.
Like this:
static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
FMOD_RESULT result;
switch (cmd) {
case APP_CMD_START:
result = mpSystem->mixerResume();
break;
case APP_CMD_STOP:
result = mpSystem->mixerSuspend();
break;
}
}
This is the full native code:
#include <jni.h>
#include <android_native_app_glue.h>
#include "fmod.hpp"
struct engine {
struct android_app* app;
};
FMOD::System *mpSystem = 0;
FMOD::Sound *sound = 0;
static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) {
// play sound
if(sound != 0)
{
FMOD_RESULT result;
FMOD::Channel *channel = 0;
result = mpSystem->playSound(sound, 0, false, &channel);
}
return 0;
}
static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
FMOD_RESULT result;
switch (cmd) {
case APP_CMD_START:
result = mpSystem->mixerResume();
break;
case APP_CMD_STOP:
result = mpSystem->mixerSuspend();
break;
}
}
void android_main(struct android_app* state) {
if(mpSystem == 0)
{
FMOD_RESULT result;
void *extradriverdata = 0;
result = FMOD::System_Create(&mpSystem);
result = mpSystem->init(32, FMOD_INIT_NORMAL, extradriverdata);
result = mpSystem->createSound("/storage/extSdCard/sdMedia/sound/concrete_break2.wav", FMOD_HARDWARE, 0, &sound);
result = sound->setMode(FMOD_LOOP_OFF);
}
struct engine engine;
app_dummy();
memset(&engine, 0, sizeof(engine));
state->userData = &engine;
state->onAppCmd = engine_handle_cmd;
state->onInputEvent = engine_handle_input;
engine.app = state;
while (1) {
int ident;
int events;
struct android_poll_source* source;
while ((ident=ALooper_pollAll(0, 0, &events, (void**)&source)) >= 0)
{
if (source != 0) {
source->process(state, source);
}
// Check if we are exiting.
if (state->destroyRequested != 0) {
return;
}
}
}
}
And this is the Java code:
package com.example.native_activity;
import android.os.Bundle;
import org.fmod.FMODAudioDevice;
public class DummyActivity extends android.app.NativeActivity
{
@Override
protected void onDestroy()
{
FMODAudioDevice.close();
super.onDestroy();
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
FMODAudioDevice.init(this);
}
static
{
System.loadLibrary("fmodL");
System.loadLibrary("native-activity");
}
}