[Android] jni: Subscribe to MediaListItemAdded and MediaListItemDeleted
Edward Wang
git at videolan.org
Tue Aug 28 15:33:01 CEST 2012
vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Mon Aug 27 16:20:36 2012 -0400| [c8f6455ae167a0d9002977decbc01d8d2f251d6d] | committer: Edward Wang
jni: Subscribe to MediaListItemAdded and MediaListItemDeleted
So that we can use playlists and history view in GUI.
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=c8f6455ae167a0d9002977decbc01d8d2f251d6d
---
vlc-android/jni/libvlcjni.c | 32 ++++++++++++++++++++
vlc-android/src/org/videolan/vlc/EventManager.java | 4 +--
2 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
index 1d49ea8..bfaddc5 100644
--- a/vlc-android/jni/libvlcjni.c
+++ b/vlc-android/jni/libvlcjni.c
@@ -279,6 +279,29 @@ static void vlc_event_callback(const libvlc_event_t *ev, void *data)
jstring sData = (*env)->NewStringUTF(env, "data");
(*env)->CallVoidMethod(env, bundle, putInt, sData, ev->u.media_player_vout.new_count);
(*env)->DeleteLocalRef(env, sData);
+ } else if(ev->type == libvlc_MediaListItemAdded ||
+ ev->type == libvlc_MediaListItemDeleted ) {
+ jstring item_uri = (*env)->NewStringUTF(env, "item_uri");
+ jstring item_index = (*env)->NewStringUTF(env, "item_index");
+ char* mrl = libvlc_media_get_mrl(
+ ev->type == libvlc_MediaListItemAdded ?
+ ev->u.media_list_item_added.item :
+ ev->u.media_list_item_deleted.item
+ );
+ jstring item_uri_value = (*env)->NewStringUTF(env, mrl);
+ jint item_index_value;
+ if(ev->type == libvlc_MediaListItemAdded)
+ item_index_value = ev->u.media_list_item_added.index;
+ else
+ item_index_value = ev->u.media_list_item_deleted.index;
+
+ (*env)->CallVoidMethod(env, bundle, putString, item_uri, item_uri_value);
+ (*env)->CallVoidMethod(env, bundle, putInt, item_index, item_index_value);
+
+ (*env)->DeleteLocalRef(env, item_uri);
+ (*env)->DeleteLocalRef(env, item_uri_value);
+ (*env)->DeleteLocalRef(env, item_index);
+ free(mrl);
}
/* Get the object class */
@@ -424,6 +447,15 @@ void Java_org_videolan_vlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz, jboolean
return;
}
+ /* Connect the event manager */
+ libvlc_event_manager_t *ev = libvlc_media_list_event_manager(pointer);
+ static const libvlc_event_type_t mp_events[] = {
+ libvlc_MediaListItemAdded,
+ libvlc_MediaListItemDeleted,
+ };
+ for(int i = 0; i < (sizeof(mp_events) / sizeof(*mp_events)); i++)
+ libvlc_event_attach(ev, mp_events[i], vlc_event_callback, myVm);
+
setLong(env, thiz, "mMediaListInstance", (jlong)pointer);
}
diff --git a/vlc-android/src/org/videolan/vlc/EventManager.java b/vlc-android/src/org/videolan/vlc/EventManager.java
index cbb9184..d5eb298 100644
--- a/vlc-android/src/org/videolan/vlc/EventManager.java
+++ b/vlc-android/src/org/videolan/vlc/EventManager.java
@@ -59,9 +59,9 @@ public class EventManager {
//public static final int MediaPlayerLengthChanged = 0x111;
public static final int MediaPlayerVout = 0x112;
- //public static final int MediaListItemAdded = 0x200;
+ public static final int MediaListItemAdded = 0x200;
//public static final int MediaListWillAddItem = 0x201;
- //public static final int MediaListItemDeleted = 0x202;
+ public static final int MediaListItemDeleted = 0x202;
//public static final int MediaListWillDeleteItem = 0x203;
//public static final int MediaListViewItemAdded = 0x300;
More information about the Android
mailing list