[Android] Media: add getType()

Thomas Guillem git at videolan.org
Wed Mar 25 16:43:47 CET 2015


vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Feb  3 15:28:59 2015 +0100| [c4afc5be63e2cbd42d51d72751508390080836e9] | committer: Thomas Guillem

Media: add getType()

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

 libvlc/jni/libvlcjni-media.c              |   14 ++++++++++++++
 libvlc/src/org/videolan/libvlc/Media.java |   26 ++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/libvlc/jni/libvlcjni-media.c b/libvlc/jni/libvlcjni-media.c
index 0c3d736..ac8ad66 100644
--- a/libvlc/jni/libvlcjni-media.c
+++ b/libvlc/jni/libvlcjni-media.c
@@ -460,3 +460,17 @@ Java_org_videolan_libvlc_Media_nativeGetDuration(JNIEnv *env, jobject thiz)
 
     return libvlc_media_get_duration(p_obj->u.p_m);
 }
+
+jint
+Java_org_videolan_libvlc_Media_nativeGetType(JNIEnv *env, jobject thiz)
+{
+    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);
+
+    if (!p_obj)
+    {
+        throw_IllegalStateException(env, "can't get Media instance");
+        return 0;
+    }
+
+    return libvlc_media_get_type(p_obj->u.p_m);
+}
diff --git a/libvlc/src/org/videolan/libvlc/Media.java b/libvlc/src/org/videolan/libvlc/Media.java
index afa7c42..3f42614 100644
--- a/libvlc/src/org/videolan/libvlc/Media.java
+++ b/libvlc/src/org/videolan/libvlc/Media.java
@@ -24,6 +24,18 @@ public final class Media extends VLCObject {
     private final static String TAG = "LibVLC/Media";
 
     /**
+     * libvlc_media_type_t
+     */
+    public static class Type {
+        public static final int Unknown = 0;
+        public static final int File = 1;
+        public static final int Directory = 2;
+        public static final int Disc = 3;
+        public static final int Stream = 4;
+        public static final int Playlist = 5;
+    }
+
+    /**
      * see libvlc_meta_t
      */
     public static class Meta {
@@ -207,6 +219,7 @@ public final class Media extends VLCObject {
     private Track mNativeTracks[] = null;
     private long mDuration;
     private int mState = State.NothingSpecial;
+    private int mType = Type.Unknown;
 
     /**
      * Create a Media from libVLC and a mrl.
@@ -217,6 +230,7 @@ public final class Media extends VLCObject {
     public Media(LibVLC libVLC, String mrl) {
         nativeNewFromMrl(libVLC, mrl);
         mMrl = nativeGetMrl();
+        mType = nativeGetType();
     }
 
     /**
@@ -230,6 +244,7 @@ public final class Media extends VLCObject {
         nativeNewFromMediaList(ml, index);
         mMrl = nativeGetMrl();
         mNativeMetas = nativeGetMetas();
+        mType = nativeGetType();
     }
 
     @Override
@@ -299,6 +314,7 @@ public final class Media extends VLCObject {
                 throw new IllegalStateException("native metas size doesn't match");
             mDuration = nativeGetDuration();
             mState = nativeGetState();
+            mType = nativeGetType();
         }
     }
 
@@ -362,6 +378,15 @@ public final class Media extends VLCObject {
     }
 
     /**
+     * Get the type of the media
+     *
+     * @see {@link Type}
+     */
+    public synchronized int getType() {
+        return mType;
+    }
+
+    /**
      * Get the Track count.
      */
     public synchronized int getTrackCount() {
@@ -414,4 +439,5 @@ public final class Media extends VLCObject {
     private native String[] nativeGetMetas();
     private native Track[] nativeGetTracks();
     private native long nativeGetDuration();
+    private native int nativeGetType();
 }



More information about the Android mailing list