Commit 1044f6a5 authored by Edward Wang's avatar Edward Wang

libvlcjni: refactor event handler code

To prevent code duplication for use in another class soon
parent fb6f219a
......@@ -115,6 +115,23 @@ void setString(JNIEnv *env, jobject item, const char* field, const char* text) {
(*env)->SetObjectField(env, item, fieldId, jstr);
}
jobject getEventHandlerReference(JNIEnv *env, jobject thiz, jobject eventHandler)
{
jclass cls = (*env)->GetObjectClass(env, eventHandler);
if (!cls) {
LOGE("setEventHandler: failed to get class reference");
return NULL;
}
jmethodID methodID = (*env)->GetMethodID(env, cls, "callback", "(ILandroid/os/Bundle;)V");
if (!methodID) {
LOGE("setEventHandler: failed to get the callback method");
return NULL;
}
return (*env)->NewGlobalRef(env, eventHandler);
}
static void debug_buffer_log(void *data, int level, const char *fmt, va_list ap)
{
bool isAttached = false;
......
......@@ -326,19 +326,7 @@ void Java_org_videolan_libvlc_LibVLC_setEventHandler(JNIEnv *env, jobject thiz,
eventHandlerInstance = NULL;
}
jclass cls = (*env)->GetObjectClass(env, eventHandler);
if (!cls) {
LOGE("setEventHandler: failed to get class reference");
return;
}
jmethodID methodID = (*env)->GetMethodID(env, cls, "callback", "(ILandroid/os/Bundle;)V");
if (!methodID) {
LOGE("setEventHandler: failed to get the callback method");
return;
}
eventHandlerInstance = (*env)->NewGlobalRef(env, eventHandler);
eventHandlerInstance = getEventHandlerReference(env, thiz, eventHandler);
}
static void create_player_and_play(JNIEnv* env, jobject thiz,
......
......@@ -39,6 +39,8 @@ void setFloat(JNIEnv *env, jobject item, const char* field, jfloat value);
void setString(JNIEnv *env, jobject item, const char* field, const char* text);
jobject getEventHandlerReference(JNIEnv *env, jobject thiz, jobject eventHandler);
void debug_log(void *data, int level, const libvlc_log_t *ctx, const char *fmt, va_list ap);
#endif // LIBVLCJNI_UTILS_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment