[Android] libvlcjni: fix old event handler

Thomas Guillem git at videolan.org
Wed May 27 12:37:57 CEST 2015


vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed May 27 11:25:10 2015 +0200| [45a3dbd31f7f749b639f67b20cb28289255e4b24] | committer: Jean-Baptiste Kempf

libvlcjni: fix old event handler

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=45a3dbd31f7f749b639f67b20cb28289255e4b24
---

 libvlc/jni/libvlcjni-mediaplayer.c |   34 +++++++++++++++++++++++++++++++++-
 libvlc/jni/libvlcjni.c             |    4 +++-
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/libvlc/jni/libvlcjni-mediaplayer.c b/libvlc/jni/libvlcjni-mediaplayer.c
index 8034c80..13941eb 100644
--- a/libvlc/jni/libvlcjni-mediaplayer.c
+++ b/libvlc/jni/libvlcjni-mediaplayer.c
@@ -27,7 +27,7 @@
 #define THREAD_NAME "libvlcjni"
 JNIEnv *jni_get_env(const char *name);
 
-static jobject eventHandlerInstance = NULL;
+extern jobject eventHandlerInstance;
 
 /* TODO REMOVE */
 static void vlc_event_callback(const libvlc_event_t *ev, void *data)
@@ -202,6 +202,23 @@ Java_org_videolan_libvlc_MediaPlayer_nativeRelease(JNIEnv *env, jobject thiz)
 {
     GET_INSTANCE(p_obj)
 
+    /* TODO: REMOVE */
+    libvlc_event_manager_t *ev = libvlc_media_player_event_manager(p_obj->u.p_mp);
+    static const libvlc_event_type_t mp_events[] = {
+        libvlc_MediaPlayerPlaying,
+        libvlc_MediaPlayerPaused,
+        libvlc_MediaPlayerEndReached,
+        libvlc_MediaPlayerStopped,
+        libvlc_MediaPlayerVout,
+        libvlc_MediaPlayerPositionChanged,
+        libvlc_MediaPlayerTimeChanged,
+        libvlc_MediaPlayerEncounteredError,
+        libvlc_MediaPlayerESAdded,
+        libvlc_MediaPlayerESDeleted,
+    };
+
+    for(int i = 0; i < (sizeof(mp_events) / sizeof(*mp_events)); i++)
+        libvlc_event_detach(ev, mp_events[i], vlc_event_callback, NULL);
     libvlc_media_player_release(p_obj->u.p_mp);
 
     VLCJniObject_release(env, thiz, p_obj);
@@ -261,6 +278,21 @@ Java_org_videolan_libvlc_MediaPlayer_stop(JNIEnv *env, jobject thiz)
 {
     GET_INSTANCE(p_obj)
 
+    /* TODO: REMOVE */
+    libvlc_media_t* p_md = libvlc_media_player_get_media(p_obj->u.p_mp);
+    if (p_md)
+    {
+        libvlc_event_manager_t *ev_media = libvlc_media_event_manager(p_md);
+        static const libvlc_event_type_t mp_media_events[] = {
+            libvlc_MediaParsedChanged,
+            libvlc_MediaMetaChanged,
+        };
+        for(int i = 0; i < (sizeof(mp_media_events) / sizeof(*mp_media_events)); i++)
+            libvlc_event_detach(ev_media, mp_media_events[i], vlc_event_callback, NULL);
+        libvlc_media_release(p_md);
+        libvlc_media_player_set_media(p_obj->u.p_md, NULL);
+    }
+
     libvlc_media_player_stop(p_obj->u.p_mp);
 }
 
diff --git a/libvlc/jni/libvlcjni.c b/libvlc/jni/libvlcjni.c
index b8921ad..ba2cbf1 100644
--- a/libvlc/jni/libvlcjni.c
+++ b/libvlc/jni/libvlcjni.c
@@ -62,7 +62,7 @@ libvlc_instance_t *getLibVlcInstance(JNIEnv *env, jobject thiz)
     return (libvlc_instance_t*)(intptr_t)getLong(env, thiz, "mLibVlcInstance");
 }
 
-static jobject eventHandlerInstance = NULL;
+jobject eventHandlerInstance = NULL;
 
 
 /* Pointer to the Java virtual machine
@@ -414,6 +414,7 @@ void Java_org_videolan_libvlc_LibVLC_nativeDestroy(JNIEnv *env, jobject thiz)
     setLong(env, thiz, "mLibVlcInstance", 0);
 }
 
+/* TODO REMOVE */
 void Java_org_videolan_libvlc_LibVLC_detachEventHandler(JNIEnv *env, jobject thiz)
 {
     if (eventHandlerInstance != NULL) {
@@ -422,6 +423,7 @@ void Java_org_videolan_libvlc_LibVLC_detachEventHandler(JNIEnv *env, jobject thi
     }
 }
 
+/* TODO REMOVE */
 void Java_org_videolan_libvlc_LibVLC_setEventHandler(JNIEnv *env, jobject thiz, jobject eventHandler)
 {
     if (eventHandlerInstance != NULL) {



More information about the Android mailing list