[Android] libvlc: Media: separate path and Uri constructors

Thomas Guillem git at videolan.org
Wed May 27 17:00:12 CEST 2015


vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed May 27 16:46:48 2015 +0200| [14d11045a2bc1ce77d0949c2b63e40d1cfebfcb0] | committer: Thomas Guillem

libvlc: Media: separate path and Uri constructors

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

 libvlc/jni/libvlcjni-media.c              |   29 +++++++++++++++++++++--------
 libvlc/src/org/videolan/libvlc/Media.java |   21 +++++++++++++++------
 2 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/libvlc/jni/libvlcjni-media.c b/libvlc/jni/libvlcjni-media.c
index b6aec41..ea2ac07 100644
--- a/libvlc/jni/libvlcjni-media.c
+++ b/libvlc/jni/libvlcjni-media.c
@@ -157,16 +157,16 @@ Media_nativeNewCommon(JNIEnv *env, jobject thiz, vlcjni_object *p_obj)
                               m_events);
 }
 
-void
-Java_org_videolan_libvlc_Media_nativeNewFromMrl(JNIEnv *env, jobject thiz,
-                                                jobject libVlc, jstring jmrl)
+static void
+Media_nativeNewFromCb(JNIEnv *env, jobject thiz, jobject libVlc, jstring jmrl,
+                      libvlc_media_t *(*pf)(libvlc_instance_t*, const char *))
 {
     vlcjni_object *p_obj;
     const char* p_mrl;
 
     if (!jmrl || !(p_mrl = (*env)->GetStringUTFChars(env, jmrl, 0)))
     {
-        throw_IllegalArgumentException(env, "mrl invalid");
+        throw_IllegalArgumentException(env, "path or location invalid");
         return;
     }
 
@@ -177,10 +177,7 @@ Java_org_videolan_libvlc_Media_nativeNewFromMrl(JNIEnv *env, jobject thiz,
         return;
     }
 
-    if (p_mrl[0] == '/' || p_mrl[0] == '\\')
-        p_obj->u.p_m = libvlc_media_new_path(p_obj->p_libvlc, p_mrl);
-    else
-        p_obj->u.p_m = libvlc_media_new_location(p_obj->p_libvlc, p_mrl);
+    p_obj->u.p_m = pf(p_obj->p_libvlc, p_mrl);
 
     (*env)->ReleaseStringUTFChars(env, jmrl, p_mrl);
 
@@ -188,6 +185,22 @@ Java_org_videolan_libvlc_Media_nativeNewFromMrl(JNIEnv *env, jobject thiz,
 }
 
 void
+Java_org_videolan_libvlc_Media_nativeNewFromPath(JNIEnv *env, jobject thiz,
+                                                 jobject libVlc, jstring jpath)
+{
+    Media_nativeNewFromCb(env, thiz, libVlc, jpath, libvlc_media_new_path);
+}
+
+void
+Java_org_videolan_libvlc_Media_nativeNewFromLocation(JNIEnv *env, jobject thiz,
+                                                     jobject libVlc,
+                                                     jstring jlocation)
+{
+    Media_nativeNewFromCb(env, thiz, libVlc, jlocation,
+                          libvlc_media_new_location);
+}
+
+void
 Java_org_videolan_libvlc_Media_nativeNewFromMediaList(JNIEnv *env, jobject thiz,
                                                       jobject ml, jint index)
 {
diff --git a/libvlc/src/org/videolan/libvlc/Media.java b/libvlc/src/org/videolan/libvlc/Media.java
index 0648311..63a15f0 100644
--- a/libvlc/src/org/videolan/libvlc/Media.java
+++ b/libvlc/src/org/videolan/libvlc/Media.java
@@ -224,19 +224,27 @@ public final class Media extends VLCObject {
     private int mType = Type.Unknown;
 
     /**
-     * Create a Media from libVLC and a mrl.
+     * Create a Media from libVLC and a local path starting with '/'.
      *
      * @param libVLC
-     * @param mrl
+     * @param path
      */
-    public Media(LibVLC libVLC, String mrl) {
-        nativeNewFromMrl(libVLC, mrl);
+    public Media(LibVLC libVLC, String path) {
+        nativeNewFromPath(libVLC, path);
         mMrl = nativeGetMrl();
         mType = nativeGetType();
     }
 
+    /**
+     * Create a Media from libVLC and a Uri
+     *
+     * @param libVLC
+     * @param uri
+     */
     public Media(LibVLC libVLC, Uri uri) {
-        this(libVLC, uri.toString());
+        nativeNewFromLocation(libVLC, uri.toString());
+        mMrl = nativeGetMrl();
+        mType = nativeGetType();
     }
 
     /**
@@ -434,7 +442,8 @@ public final class Media extends VLCObject {
     }
 
     /* JNI */
-    private native void nativeNewFromMrl(LibVLC libVLC, String mrl);
+    private native void nativeNewFromPath(LibVLC libVLC, String path);
+    private native void nativeNewFromLocation(LibVLC libVLC, String location);
     private native void nativeNewFromMediaList(MediaList ml, int index);
     private native void nativeRelease();
     private native boolean nativeParseAsync(int flags);



More information about the Android mailing list