[Android] libvlc: remove java medialist dependency from native code
Sébastien Toque
git at videolan.org
Sun Dec 8 14:32:17 CET 2013
vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Sun Dec 8 14:31:02 2013 +0100| [0ab8141e2032c53ef1d1354bb41979c297a107fa] | committer: Sébastien Toque
libvlc: remove java medialist dependency from native code
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=0ab8141e2032c53ef1d1354bb41979c297a107fa
---
vlc-android/jni/libvlcjni.c | 42 ++++++++---------------
vlc-android/src/org/videolan/libvlc/LibVLC.java | 11 ++++--
2 files changed, 22 insertions(+), 31 deletions(-)
diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
index aae6fb5..4c92ccd 100644
--- a/vlc-android/jni/libvlcjni.c
+++ b/vlc-android/jni/libvlcjni.c
@@ -322,8 +322,9 @@ void Java_org_videolan_libvlc_LibVLC_setEventHandler(JNIEnv *env, jobject thiz,
eventHandlerInstance = getEventHandlerReference(env, thiz, eventHandler);
}
-static void create_player_and_play(JNIEnv* env, jobject thiz,
- jlong instance, int position) {
+void Java_org_videolan_libvlc_LibVLC_playMrl(JNIEnv *env, jobject thiz, jlong instance,
+ jstring mrl, jobjectArray mediaOptions)
+{
/* Release previous media player, if any */
releaseMediaPlayer(env, thiz);
@@ -363,43 +364,28 @@ static void create_player_and_play(JNIEnv* env, jobject thiz,
jmethodID methodID = (*env)->GetMethodID(env, cls, "applyEqualizer", "()V");
(*env)->CallVoidMethod(env, thiz, methodID);
- setInt(env, thiz, "mInternalMediaPlayerIndex", (jint)position);
-
- jfieldID fid = (*env)->GetFieldID(env, cls, "mMediaList", "Lorg/videolan/libvlc/MediaList;");
- jobject list = (*env)->GetObjectField(env, thiz, fid);
- jclass clsList = (*env)->FindClass(env, "org/videolan/libvlc/MediaList");
-
- methodID = (*env)->GetMethodID(env, clsList, "getMRL", "(I)Ljava/lang/String;");
- jstring mrl = (jstring)(*env)->CallObjectMethod(env, list, methodID, (jint)position);
const char* p_mrl = (*env)->GetStringUTFChars(env, mrl, 0);
libvlc_media_t* p_md = libvlc_media_new_location((libvlc_instance_t*)(intptr_t)instance, p_mrl);
/* media options */
- methodID = (*env)->GetMethodID(env, clsList, "getMediaOptions", "(I)[Ljava/lang/String;");
- jobjectArray mediaOptions = (jobject)(*env)->CallObjectMethod(env, list, methodID, (jint)position);
- int stringCount = (*env)->GetArrayLength(env, mediaOptions);
- for(int i = 0; i < stringCount; i++) {
- jstring option = (jstring)(*env)->GetObjectArrayElement(env, mediaOptions, i);
- const char* p_st = (*env)->GetStringUTFChars(env, option, 0);
- libvlc_media_add_option(p_md, p_st); // option
- (*env)->ReleaseStringUTFChars(env, option, p_st);
+ if (mediaOptions != NULL)
+ {
+ int stringCount = (*env)->GetArrayLength(env, mediaOptions);
+ for(int i = 0; i < stringCount; i++)
+ {
+ jstring option = (jstring)(*env)->GetObjectArrayElement(env, mediaOptions, i);
+ const char* p_st = (*env)->GetStringUTFChars(env, option, 0);
+ libvlc_media_add_option(p_md, p_st); // option
+ (*env)->ReleaseStringUTFChars(env, option, p_st);
+ }
}
-
+
(*env)->ReleaseStringUTFChars(env, mrl, p_mrl);
- (*env)->DeleteLocalRef(env, mrl);
- (*env)->DeleteLocalRef(env, mediaOptions);
- (*env)->DeleteLocalRef(env, list);
- list = NULL;
libvlc_media_player_set_media(mp, p_md);
libvlc_media_player_play(mp);
}
-void Java_org_videolan_libvlc_LibVLC_playIndex(JNIEnv *env, jobject thiz,
- jlong instance, int position) {
- create_player_and_play(env, thiz, instance, position);
-}
-
jfloat Java_org_videolan_libvlc_LibVLC_getRate(JNIEnv *env, jobject thiz) {
libvlc_media_player_t* mp = getMediaPlayer(env, thiz);
if(mp)
diff --git a/vlc-android/src/org/videolan/libvlc/LibVLC.java b/vlc-android/src/org/videolan/libvlc/LibVLC.java
index 77c985e..8451aa9 100644
--- a/vlc-android/src/org/videolan/libvlc/LibVLC.java
+++ b/vlc-android/src/org/videolan/libvlc/LibVLC.java
@@ -412,7 +412,12 @@ public class LibVLC {
* @param position The index of the media
*/
public void playIndex(int position) {
- playIndex(mLibVlcInstance, position);
+ String mrl = mMediaList.getMRL(position);
+ if (mrl == null)
+ return;
+ String[] options = mMediaList.getMediaOptions(position);
+ mInternalMediaPlayerIndex = position;
+ playMrl(mLibVlcInstance, mrl, options);
}
public TrackInfo[] readTracksInfo(String mrl) {
@@ -475,9 +480,9 @@ public class LibVLC {
}
/**
- * Play an index in the native media list (playlist)
+ * Play an mrl
*/
- private native void playIndex(long instance, int position);
+ private native void playMrl(long instance, String mrl, String[] mediaOptions);
/**
* Returns true if any media is playing
More information about the Android
mailing list