[Android] libvlcjni: return the audio track ID too

Edward Wang git at videolan.org
Fri Jan 18 01:24:29 CET 2013


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Thu Jan 17 18:14:31 2013 -0500| [1943464a8e677e4135d6304e9ea590c37eb5242d] | committer: Edward Wang

libvlcjni: return the audio track ID too

The behaviour was introduced in 2c5ee1707b1962ee3f47dbe4abb7c199aeccc022

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

 vlc-android/jni/libvlcjni.c                        |   29 ++++++++++++++++----
 vlc-android/src/org/videolan/vlc/LibVLC.java       |    3 +-
 .../vlc/gui/video/VideoPlayerActivity.java         |    3 +-
 3 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
index 8c7abea..68b937f 100644
--- a/vlc-android/jni/libvlcjni.c
+++ b/vlc-android/jni/libvlcjni.c
@@ -1034,7 +1034,7 @@ jint Java_org_videolan_vlc_LibVLC_getAudioTracksCount(JNIEnv *env, jobject thiz)
     return -1;
 }
 
-jobjectArray Java_org_videolan_vlc_LibVLC_getAudioTrackDescription(JNIEnv *env, jobject thiz)
+jobject Java_org_videolan_vlc_LibVLC_getAudioTrackDescription(JNIEnv *env, jobject thiz)
 {
     libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
     if (!mp)
@@ -1043,21 +1043,38 @@ jobjectArray Java_org_videolan_vlc_LibVLC_getAudioTrackDescription(JNIEnv *env,
     int i_nbTracks = libvlc_audio_get_track_count(mp) - 1;
     if (i_nbTracks < 0)
         i_nbTracks = 0;
-    jobjectArray array = (*env)->NewObjectArray(env, i_nbTracks,
-            (*env)->FindClass(env, "java/lang/String"),
-            NULL);
+    jclass mapClass = (*env)->FindClass(env, "java/util/Map");
+    jclass hashMapClass = (*env)->FindClass(env, "java/util/HashMap");
+    jmethodID mapPut = (*env)->GetMethodID(env, mapClass, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
+    /*
+     * "What are you building? Lay your hand on it. Where is it?"
+     * We need a concrete map to start
+     */
+    jmethodID mapInit = (*env)->GetMethodID(env, hashMapClass, "<init>", "()V");
+    jclass integerCls = (*env)->FindClass(env, "java/lang/Integer");
+    jmethodID integerConstructor = (*env)->GetMethodID(env, integerCls, "<init>", "(I)V");
+
+    jobject audioTrackMap = (*env)->NewObject(env, hashMapClass, mapInit);
 
     libvlc_track_description_t *first = libvlc_audio_get_track_description(mp);
     libvlc_track_description_t *desc = first != NULL ? first->p_next : NULL;
     unsigned i;
     for (i = 0; i < i_nbTracks; ++i)
     {
+        // store audio track ID and name in a map as <ID, Track Name>
+        jobject track_id = (*env)->NewObject(env, integerCls, integerConstructor, desc->i_id);
         jstring name = (*env)->NewStringUTF(env, desc->psz_name);
-        (*env)->SetObjectArrayElement(env, array, i, name);
+        (*env)->CallObjectMethod(env, audioTrackMap, mapPut, track_id, name);
         desc = desc->p_next;
     }
     libvlc_track_description_list_release(first);
-    return array;
+
+    // Clean up local references
+    (*env)->DeleteLocalRef(env, mapClass);
+    (*env)->DeleteLocalRef(env, hashMapClass);
+    (*env)->DeleteLocalRef(env, integerCls);
+
+    return audioTrackMap;
 }
 
 jint Java_org_videolan_vlc_LibVLC_getAudioTrack(JNIEnv *env, jobject thiz)
diff --git a/vlc-android/src/org/videolan/vlc/LibVLC.java b/vlc-android/src/org/videolan/vlc/LibVLC.java
index 234420f..ac4adc3 100644
--- a/vlc-android/src/org/videolan/vlc/LibVLC.java
+++ b/vlc-android/src/org/videolan/vlc/LibVLC.java
@@ -21,6 +21,7 @@
 package org.videolan.vlc;
 
 import java.util.ArrayList;
+import java.util.Map;
 
 import org.videolan.vlc.gui.video.VideoPlayerActivity;
 
@@ -460,7 +461,7 @@ public class LibVLC {
 
     public native int getAudioTracksCount();
 
-    public native String[] getAudioTrackDescription();
+    public native Map<Integer,String> getAudioTrackDescription();
 
     public native int getAudioTrack();
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index a81155d..090e924 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -26,6 +26,7 @@ import java.lang.reflect.Method;
 import java.net.URLDecoder;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Map;
 
 import org.videolan.vlc.AudioServiceController;
 import org.videolan.vlc.DatabaseManager;
@@ -171,7 +172,7 @@ public class VideoPlayerActivity extends Activity {
 
     // Tracks & Subtitles
     private String[] mAudioTracksLibVLC;
-    private ArrayList<String> mAudioTracksList;
+    private Map<Integer,String> mAudioTracksList;
     private String[] mSubtitleTracksLibVLC;
     private ArrayList<String> mSubtitleTracksList;
 



More information about the Android mailing list