[Android] libvlcjni: add media list selection

Edward Wang git at videolan.org
Wed Aug 28 16:34:19 CEST 2013


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Tue Aug 27 22:06:40 2013 +0200| [ff336612d259be1fb8d10c39e50a31a2c458f017] | committer: Edward Wang

libvlcjni: add media list selection

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

 vlc-android/jni/libvlcjni-medialist.c           |   16 ++++-----
 vlc-android/jni/libvlcjni-track.c               |    4 +--
 vlc-android/jni/libvlcjni-util.c                |    5 +++
 vlc-android/jni/libvlcjni.c                     |   10 ++++--
 vlc-android/jni/utils.h                         |    2 +-
 vlc-android/src/org/videolan/libvlc/LibVLC.java |   41 +++++++++++++++++++++--
 6 files changed, 59 insertions(+), 19 deletions(-)

diff --git a/vlc-android/jni/libvlcjni-medialist.c b/vlc-android/jni/libvlcjni-medialist.c
index 4c33356..55c7333 100644
--- a/vlc-android/jni/libvlcjni-medialist.c
+++ b/vlc-android/jni/libvlcjni-medialist.c
@@ -30,10 +30,6 @@
 /** Unique Java VM instance, as defined in libvlcjni.c */
 extern JavaVM *myVm;
 
-libvlc_media_list_t* getMediaList(JNIEnv *env, jobject thiz) {
-    return (libvlc_media_list_t*)(intptr_t)getLong(env, thiz, "mMediaListInstance");
-}
-
 // data is the MediaList Java object of the media list
 static void vlc_media_list_event_callback(const libvlc_event_t *ev, void *data)
 {
@@ -134,20 +130,20 @@ jlong Java_org_videolan_libvlc_MediaList_init(JNIEnv *env, jobject thiz, jobject
 }
 
 void Java_org_videolan_libvlc_MediaList_nativeDestroy(JNIEnv *env, jobject thiz) {
-    libvlc_media_list_t* p_ml = getMediaList(env, thiz);
+    libvlc_media_list_t* p_ml = getMediaListFromJava(env, thiz);
     libvlc_media_list_release(p_ml);
     (*env)->DeleteGlobalRef(env, (jobject)(intptr_t)getLong(env, thiz, "mEventHanderGlobalRef"));
 }
 
 void Java_org_videolan_libvlc_MediaList_remove(JNIEnv *env, jobject thiz, jint position) {
-    libvlc_media_list_t* p_ml = getMediaList(env, thiz);
+    libvlc_media_list_t* p_ml = getMediaListFromJava(env, thiz);
     libvlc_media_list_lock(p_ml);
     libvlc_media_list_remove_index(p_ml, position);
     libvlc_media_list_unlock(p_ml);
 }
 
 void Java_org_videolan_libvlc_MediaList_add(JNIEnv *env, jobject thiz, jobject libvlcInstance, jstring mrl) {
-    libvlc_media_list_t* p_ml = getMediaList(env, thiz);
+    libvlc_media_list_t* p_ml = getMediaListFromJava(env, thiz);
     const char* p_mrl = (*env)->GetStringUTFChars(env, mrl, NULL);
     libvlc_media_t *p_md = libvlc_media_new_location((libvlc_instance_t*)(intptr_t)getLong(env, libvlcInstance, "mLibVlcInstance"), p_mrl);
     libvlc_media_list_lock(p_ml);
@@ -158,7 +154,7 @@ void Java_org_videolan_libvlc_MediaList_add(JNIEnv *env, jobject thiz, jobject l
 }
 
 void Java_org_videolan_libvlc_MediaList_insert(JNIEnv *env, jobject thiz, jobject libvlcInstance, jint position, jstring mrl) {
-    libvlc_media_list_t* p_ml = getMediaList(env, thiz);
+    libvlc_media_list_t* p_ml = getMediaListFromJava(env, thiz);
     const char* p_mrl = (*env)->GetStringUTFChars(env, mrl, NULL);
     libvlc_media_t *p_md = libvlc_media_new_location((libvlc_instance_t*)(intptr_t)getLong(env, libvlcInstance, "mLibVlcInstance"), p_mrl);
     libvlc_media_list_lock(p_ml);
@@ -169,7 +165,7 @@ void Java_org_videolan_libvlc_MediaList_insert(JNIEnv *env, jobject thiz, jobjec
 }
 
 jint Java_org_videolan_libvlc_MediaList_size(JNIEnv *env, jobject thiz) {
-    libvlc_media_list_t* p_ml = getMediaList(env, thiz);
+    libvlc_media_list_t* p_ml = getMediaListFromJava(env, thiz);
     libvlc_media_list_lock(p_ml);
     int count = libvlc_media_list_count(p_ml);
     libvlc_media_list_unlock(p_ml);
@@ -177,7 +173,7 @@ jint Java_org_videolan_libvlc_MediaList_size(JNIEnv *env, jobject thiz) {
 }
 
 jstring Java_org_videolan_libvlc_MediaList_getMRL(JNIEnv *env, jobject thiz, jint position) {
-    libvlc_media_list_t* p_ml = getMediaList(env, thiz);
+    libvlc_media_list_t* p_ml = getMediaListFromJava(env, thiz);
     libvlc_media_list_lock(p_ml);
     libvlc_media_t* p_md = libvlc_media_list_item_at_index(p_ml, position);
     libvlc_media_list_unlock(p_ml);
diff --git a/vlc-android/jni/libvlcjni-track.c b/vlc-android/jni/libvlcjni-track.c
index 6514329..bc38025 100644
--- a/vlc-android/jni/libvlcjni-track.c
+++ b/vlc-android/jni/libvlcjni-track.c
@@ -198,9 +198,9 @@ jobjectArray Java_org_videolan_libvlc_LibVLC_readTracksInfo(JNIEnv *env, jobject
 
 
 jobjectArray Java_org_videolan_libvlc_LibVLC_readTracksInfoPosition(JNIEnv *env, jobject thiz,
-                                                                    jint position)
+                                                                    jobject mlJ, jint position)
 {
-    libvlc_media_list_t* p_mlist = getMediaList(env, thiz);
+    libvlc_media_list_t* p_mlist = getMediaListFromJava(env, mlJ);
     libvlc_media_t *p_m = libvlc_media_list_item_at_index( p_mlist, position );
     if (p_m == NULL) {
         LOGE("Could not load get media @ position %d!", position);
diff --git a/vlc-android/jni/libvlcjni-util.c b/vlc-android/jni/libvlcjni-util.c
index 3d86102..e46e54d 100644
--- a/vlc-android/jni/libvlcjni-util.c
+++ b/vlc-android/jni/libvlcjni-util.c
@@ -115,6 +115,11 @@ void setString(JNIEnv *env, jobject item, const char* field, const char* text) {
     (*env)->SetObjectField(env, item, fieldId, jstr);
 }
 
+// Returns the libvlc_media_list_t of a MediaList object
+libvlc_media_list_t* getMediaListFromJava(JNIEnv *env, jobject obj) {
+    return (libvlc_media_list_t*)(intptr_t)getLong(env, obj, "mMediaListInstance");
+}
+
 jobject getEventHandlerReference(JNIEnv *env, jobject thiz, jobject eventHandler)
 {
     jclass cls = (*env)->GetObjectClass(env, eventHandler);
diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
index 6d37579..1ff013a 100644
--- a/vlc-android/jni/libvlcjni.c
+++ b/vlc-android/jni/libvlcjni.c
@@ -74,9 +74,13 @@ libvlc_media_t *new_media(jlong instance, JNIEnv *env, jobject thiz, jstring fil
     return p_md;
 }
 
-libvlc_media_list_t *getMediaList(JNIEnv *env, jobject thiz)
-{
-    return (libvlc_media_list_t*)(intptr_t)getLong(env, thiz, "mMediaListInstance");
+// Get the current media list being followed
+libvlc_media_list_t* getMediaList(JNIEnv *env, jobject thiz) {
+    jclass clazz = (*env)->GetObjectClass(env, thiz);
+    jfieldID fieldMP = (*env)->GetFieldID(env, clazz,
+                                          "mMediaList", "Lorg/videolan/libvlc/MediaList;");
+    jobject javaML = (*env)->GetObjectField(env, thiz, fieldMP);
+    return getMediaListFromJava(env, javaML);
 }
 
 libvlc_media_player_t *getMediaPlayer(JNIEnv *env, jobject thiz)
diff --git a/vlc-android/jni/utils.h b/vlc-android/jni/utils.h
index 43ffd82..8d8ef36 100644
--- a/vlc-android/jni/utils.h
+++ b/vlc-android/jni/utils.h
@@ -23,7 +23,7 @@
 
 libvlc_media_t *new_media(jlong instance, JNIEnv *env, jobject thiz, jstring fileLocation, bool noOmx, bool noVideo);
 
-libvlc_media_list_t *getMediaList(JNIEnv *env, jobject thiz);
+libvlc_media_list_t* getMediaListFromJava(JNIEnv *env, jobject obj);
 
 libvlc_media_player_t *getMediaPlayer(JNIEnv *env, jobject thiz);
 
diff --git a/vlc-android/src/org/videolan/libvlc/LibVLC.java b/vlc-android/src/org/videolan/libvlc/LibVLC.java
index 03c7345..ec0f809 100644
--- a/vlc-android/src/org/videolan/libvlc/LibVLC.java
+++ b/vlc-android/src/org/videolan/libvlc/LibVLC.java
@@ -42,7 +42,8 @@ public class LibVLC {
     private int mInternalMediaPlayerIndex = 0; // Read-only, reserved for JNI
     private long mInternalMediaPlayerInstance = 0; // Read-only, reserved for JNI
 
-    private MediaList mMediaList;
+    private MediaList mMediaList; // Pointer to media list being followed
+    private MediaList mPrimaryList; // Primary/default media list; see getPrimaryMediaList()
 
     /** Buffer for VLC messages */
     private StringBuffer mDebugLogBuffer;
@@ -147,6 +148,40 @@ public class LibVLC {
     }
 
     /**
+     * Set the media list for LibVLC to follow.
+     *
+     * @param mediaList The media list object to follow
+     */
+    public void setMediaList(MediaList mediaList) {
+        mMediaList = mediaList;
+    }
+
+    /**
+     * Sets LibVLC to follow the default media list (see below)
+     */
+    public void setMediaList() {
+        mMediaList = mPrimaryList;
+    }
+
+    /**
+     * Gets the primary media list, or the "currently playing" list.
+     * Not to be confused with the media list pointer from above, which
+     * refers the the MediaList object that libVLC is currently following.
+     * This list is just one out of many lists that it can be pointed towards.
+     *
+     * This list will be used for lists of songs that are not user-defined.
+     * For example: selecting a song from the Songs list, or from the list
+     * displayed after selecting an album.
+     *
+     * It is loaded as the default list.
+     *
+     * @return The primary media list
+     */
+    public MediaList getPrimaryMediaList() {
+        return mPrimaryList;
+    }
+
+    /**
      * Give to LibVLC the surface to draw the video.
      * @param f the surface to draw
      */
@@ -281,7 +316,7 @@ public class LibVLC {
                 throw new LibVlcException();
             }
             nativeInit();
-            mMediaList = new MediaList(this);
+            mMediaList = mPrimaryList = new MediaList(this);
             setEventHandler(EventHandler.getInstance());
             mIsInitialized = true;
         }
@@ -535,7 +570,7 @@ public class LibVLC {
 
     private native TrackInfo[] readTracksInfo(long instance, String mrl);
 
-    public native TrackInfo[] readTracksInfoPosition(int position);
+    public native TrackInfo[] readTracksInfoPosition(MediaList mediaList, int position);
 
     public native int getAudioTracksCount();
 



More information about the Android mailing list