[Android] enhance readTracksInfo to also retrieve Length/Artist/Album/Genre
Sébastien Toque
git at videolan.org
Sun May 13 21:23:10 CEST 2012
android | branch: master | Sébastien Toque <xilasz at gmail.com> | Sun May 13 20:35:14 2012 +0200| [f54d725277239c875a230e2e1afab49cfa0ba48b] | committer: Sébastien Toque
enhance readTracksInfo to also retrieve Length/Artist/Album/Genre
> http://git.videolan.org/gitweb.cgi/android.git/?a=commit;h=f54d725277239c875a230e2e1afab49cfa0ba48b
---
vlc-android/jni/libvlcjni.c | 33 ++++++++++++++++++-
vlc-android/src/org/videolan/vlc/TrackInfo.java | 8 +++++
.../videolan/vlc/gui/video/MediaInfoActivity.java | 3 +-
3 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
index 602d579..882f609 100644
--- a/vlc-android/jni/libvlcjni.c
+++ b/vlc-android/jni/libvlcjni.c
@@ -354,6 +354,22 @@ void setInt(JNIEnv *env, jobject item, const char* field, int value)
(*env)->SetIntField(env, item, fieldId, value);
}
+void setLong(JNIEnv *env, jobject item, const char* field, long value)
+{
+ jclass cls;
+ jfieldID fieldId;
+
+ /* Get a reference to item's class */
+ cls = (*env)->GetObjectClass(env, item);
+
+ /* Look for the instance field s in cls */
+ fieldId = (*env)->GetFieldID(env, cls, field, "J");
+ if (fieldId == NULL)
+ return;
+
+ (*env)->SetLongField(env, item, fieldId, value);
+}
+
void SetFloat(JNIEnv *env, jobject item, const char* field, float value)
{
jclass cls;
@@ -551,17 +567,30 @@ jobjectArray Java_org_videolan_vlc_LibVLC_readTracksInfo(JNIEnv *env, jobject th
libvlc_media_parse(p_m);
int i_nbTracks = libvlc_media_get_tracks_info(p_m, &p_tracks);
- jobjectArray array = (*env)->NewObjectArray(env, i_nbTracks, cls, NULL);
+ jobjectArray array = (*env)->NewObjectArray(env, i_nbTracks + 1, cls, NULL);
unsigned i;
if (array != NULL)
{
- for (i = 0; i < i_nbTracks; ++i)
+ for (i = 0; i <= i_nbTracks; ++i)
{
jobject item = (*env)->NewObject(env, cls, clsCtor);
if (item == NULL)
continue;
(*env)->SetObjectArrayElement(env, array, i, item);
+
+ // use last track for metadata
+ if (i == i_nbTracks)
+ {
+ setInt(env, item, "Type", 3 /* TYPE_META */);
+ setLong(env, item, "Length", libvlc_media_get_duration(p_m));
+ setString(env, item, "Title", libvlc_media_get_meta(p_m, libvlc_meta_Title));
+ setString(env, item, "Artist", libvlc_media_get_meta(p_m, libvlc_meta_Artist));
+ setString(env, item, "Album", libvlc_media_get_meta(p_m, libvlc_meta_Album));
+ setString(env, item, "Genre", libvlc_media_get_meta(p_m, libvlc_meta_Genre));
+ continue;
+ }
+
setInt(env, item, "Id", p_tracks[i].i_id);
setInt(env, item, "Type", p_tracks[i].i_type);
setString(env, item, "Codec", (const char*)vlc_fourcc_GetDescription(0,p_tracks[i].i_codec));
diff --git a/vlc-android/src/org/videolan/vlc/TrackInfo.java b/vlc-android/src/org/videolan/vlc/TrackInfo.java
index d5268f0..6a3c04a 100644
--- a/vlc-android/src/org/videolan/vlc/TrackInfo.java
+++ b/vlc-android/src/org/videolan/vlc/TrackInfo.java
@@ -6,6 +6,7 @@ public class TrackInfo {
public static final int TYPE_AUDIO = 0;
public static final int TYPE_VIDEO = 1;
public static final int TYPE_TEXT = 2;
+ public static final int TYPE_META = 3;
public int Type;
public int Id;
@@ -20,4 +21,11 @@ public class TrackInfo {
/* Audio */
public int Channels;
public int Samplerate;
+
+ /* MetaData */
+ public long Length;
+ public String Title;
+ public String Artist;
+ public String Album;
+ public String Genre;
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoActivity.java
index 3e782b3..6408bbf 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoActivity.java
@@ -139,7 +139,8 @@ public class MediaInfoActivity extends ListActivity {
break;
case NEW_TEXT:
for (TrackInfo track : mTracks) {
- mAdapter.add(track);
+ if (track.Type != TrackInfo.TYPE_META)
+ mAdapter.add(track);
}
break;
}
More information about the Android
mailing list