Android NDK — JNI — отладка через Logcat

Я попытался отладить C ++ через Logcat .. в myMethod() работает нормально, а в LoadPlayerA() это не так.

#define  ALOG(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)

void SuperpoweredExample::myMethod() {
ALOG("This message comes from C at line %d.", __LINE__);
}void SuperpoweredExample::LoadPlayerA(const char *audioPath, int *params) {
ALOG("This message comes from D at line %d.", __LINE__);
}

потом

extern "C" {
JNIEXPORT void Java_de_meetspot_ndktest_MainActivity_LoadPlayerA(JNIEnv *javaEnvironment, jobject self, jstring audioPath, jlongArray offsetAndLength);
JNIEXPORT void Java_de_meetspot_ndktest_MainActivity_myMethod(JNIEnv *javaEnvironment, jobject self);
}

а также

JNIEXPORT void Java_de_meetspot_ndktest_MainActivity_LoadPlayerA(JNIEnv *javaEnvironment, jobject self, jstring audioPath, jlongArray params) {
jlong *longParams = javaEnvironment->GetLongArrayElements(params, JNI_FALSE);
int arr[6];
for (int n = 0; n < 6; n++) arr[n] = longParams[n];
javaEnvironment->ReleaseLongArrayElements(params, longParams, JNI_ABORT);

const char *path = javaEnvironment->GetStringUTFChars(audioPath, JNI_FALSE);
example = new SuperpoweredExample(path, arr);
javaEnvironment->ReleaseStringUTFChars(audioPath, path);
}

JNIEXPORT void Java_de_meetspot_ndktest_MainActivity_myMethod(JNIEnv *javaEnvironment, jobject self) {
example->myMethod();
}

оба метода вызываются из Java MainActivity

textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String audioPath = "/sdcard/MP3/" + textView.getText();
File baseDir = Environment.getExternalStorageDirectory();
FileInputStream fis = null;
try {
fis = new FileInputStream(audioPath);
fd = fis.getFD();String samplerateString = null, buffersizeString = null;
if (Build.VERSION.SDK_INT >= 17) {
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
samplerateString = audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
buffersizeString = audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
}
if (samplerateString == null) samplerateString = "44100";
if (buffersizeString == null) buffersizeString = "512";

statusTxt = (TextView) findViewById(R.id.statusTxt);
File audioFile = new File(audioPath);
int length = (int) audioFile.length();
long[] params = {
0,
length,
0,
length,
Integer.parseInt(samplerateString),
Integer.parseInt(buffersizeString)
};
myMethod();
LoadPlayerA(audioPath, params);
mp3List.setVisibility(View.GONE);

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
});private native void myMethod();
private native void LoadPlayerA(String path, long[] offsetAndLength);

как это может быть??

0

Решение

Задача ещё не решена.

Другие решения


По вопросам рекламы [email protected]