Fix native method registration

This commit is contained in:
Tobias Fella 2021-08-15 00:45:51 +02:00
parent 80187812e1
commit 6c45126271

View File

@ -41,20 +41,30 @@ static void seek(JNIEnv *env, jobject thiz, jlong position)
Q_UNUSED(thiz) Q_UNUSED(thiz)
// implement seek // implement seek
} }
void registerNativeMethods() { static const JNINativeMethod methods[] {{"play", "()V", reinterpret_cast<void *>(play)},
JNINativeMethod methods[] {{"play", "()V", reinterpret_cast<void *>(play)},
{"pause", "()V", reinterpret_cast<void *>(pause)}, {"pause", "()V", reinterpret_cast<void *>(pause)},
{"stop", "()V", reinterpret_cast<void *>(stop)}, {"stop", "()V", reinterpret_cast<void *>(stop)},
{"next", "()V", reinterpret_cast<void *>(next)}, {"next", "()V", reinterpret_cast<void *>(next)},
{"seek", "(J)V", reinterpret_cast<void *>(seek)}}; {"seek", "(J)V", reinterpret_cast<void *>(seek)}};
QAndroidJniObject javaClass("org/kde/kasts/KastsActivity"); Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *)
QAndroidJniEnvironment env; {
jclass objectClass = env->GetObjectClass(javaClass.object<jobject>()); static bool initialized = false;
env->RegisterNatives(objectClass, if (initialized)
methods, return JNI_VERSION_1_6;
sizeof(methods) / sizeof(methods[0])); initialized = true;
env->DeleteLocalRef(objectClass);
JNIEnv *env = nullptr;
if (vm->GetEnv((void **)&env, JNI_VERSION_1_4) != JNI_OK) {
qWarning() << "Failed to get JNI environment.";
return -1;
}
jclass theclass = env->FindClass("org/kde/kasts/KastsActivity");
if (env->RegisterNatives(theclass, methods, sizeof(methods) / sizeof(JNINativeMethod)) < 0) {
qWarning() << "Failed to register native functions.";
return -1;
}
return JNI_VERSION_1_4;
} }
MediaSessionClient::MediaSessionClient(AudioManager *audioPlayer, QObject *parent) MediaSessionClient::MediaSessionClient(AudioManager *audioPlayer, QObject *parent)