[Android] jni: Factor readTracksInfo and add readTracksInfoPosition
Edward Wang
git at videolan.org
Tue Aug 28 17:12:42 CEST 2012
vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Wed Aug 22 17:15:11 2012 -0400| [658340cc07f153bb4c2a4610172cf07bcb359ba5] | committer: Jean-Baptiste Kempf
jni: Factor readTracksInfo and add readTracksInfoPosition
This way we can read metadata from the media list without a reparse.
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=658340cc07f153bb4c2a4610172cf07bcb359ba5
---
vlc-android/jni/libvlcjni.c | 44 +++++++++++++++++++-------
vlc-android/src/org/videolan/vlc/LibVLC.java | 2 ++
2 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
index 8ec4cb2..3af0c8e 100644
--- a/vlc-android/jni/libvlcjni.c
+++ b/vlc-android/jni/libvlcjni.c
@@ -736,8 +736,7 @@ jboolean Java_org_videolan_vlc_LibVLC_hasVideoTrack(JNIEnv *env, jobject thiz,
return JNI_FALSE;
}
-jobjectArray Java_org_videolan_vlc_LibVLC_readTracksInfo(JNIEnv *env, jobject thiz,
- jlong instance, jstring mrl)
+jobjectArray read_track_info_internal(JNIEnv *env, jobject thiz, libvlc_media_t* p_m)
{
/* get java class */
jclass cls = (*env)->FindClass( env, "org/videolan/vlc/TrackInfo" );
@@ -755,17 +754,8 @@ jobjectArray Java_org_videolan_vlc_LibVLC_readTracksInfo(JNIEnv *env, jobject th
return NULL;
}
- /* Create a new item and assign it to the media player. */
- libvlc_media_t *p_m = new_media(instance, env, thiz, mrl, false, false);
- if (p_m == NULL)
- {
- LOGE("Could not create the media!");
- return NULL;
- }
-
/* Get the tracks information of the media. */
libvlc_media_track_info_t *p_tracks;
- libvlc_media_parse(p_m);
int i_nbTracks = libvlc_media_get_tracks_info(p_m, &p_tracks);
jobjectArray array = (*env)->NewObjectArray(env, i_nbTracks + 1, cls, NULL);
@@ -813,10 +803,40 @@ jobjectArray Java_org_videolan_vlc_LibVLC_readTracksInfo(JNIEnv *env, jobject th
}
libvlc_media_tracks_info_release(p_tracks, i_nbTracks);
- libvlc_media_release(p_m);
return array;
}
+
+jobjectArray Java_org_videolan_vlc_LibVLC_readTracksInfo(JNIEnv *env, jobject thiz,
+ jlong instance, jstring mrl)
+{
+ /* Create a new item and assign it to the media player. */
+ libvlc_media_t *p_m = new_media(instance, env, thiz, mrl, false, false);
+ if (p_m == NULL)
+ {
+ LOGE("Could not create the media!");
+ return NULL;
+ }
+
+ libvlc_media_parse(p_m);
+ jobjectArray jar = read_track_info_internal(env, thiz, p_m);
+ libvlc_media_release(p_m);
+ return jar;
+}
+
+
+jobjectArray Java_org_videolan_vlc_LibVLC_readTracksInfoPosition(JNIEnv *env, jobject thiz,
+ jint position)
+{
+ libvlc_media_list_t* p_mlist = getMediaList(env, thiz);
+ 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);
+ return NULL;
+ } else
+ return read_track_info_internal(env, thiz, p_m);
+}
+
jlong Java_org_videolan_vlc_LibVLC_getLengthFromLocation(JNIEnv *env, jobject thiz,
jint i_instance, jstring fileLocation)
{
diff --git a/vlc-android/src/org/videolan/vlc/LibVLC.java b/vlc-android/src/org/videolan/vlc/LibVLC.java
index 45f722a..1e8ec98 100644
--- a/vlc-android/src/org/videolan/vlc/LibVLC.java
+++ b/vlc-android/src/org/videolan/vlc/LibVLC.java
@@ -447,6 +447,8 @@ public class LibVLC {
private native TrackInfo[] readTracksInfo(long instance, String mrl);
+ public native TrackInfo[] readTracksInfoPosition(int position);
+
public native int getAudioTracksCount();
public native String[] getAudioTrackDescription();
More information about the Android
mailing list