[Android] Devices/folders management API implementation

Geoffrey Métais git at videolan.org
Mon Nov 21 18:51:22 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Nov 21 18:04:27 2016 +0100| [d495f0764d66d1b58055f2eb29d63337ac6a9359] | committer: Geoffrey Métais

Devices/folders management API implementation

> https://code.videolan.org/videolan/vlc-android/commit/d495f0764d66d1b58055f2eb29d63337ac6a9359
---

 medialibrary/jni/AndroidMediaLibrary.cpp           | 18 ++++++++++
 medialibrary/jni/AndroidMediaLibrary.h             |  4 +++
 medialibrary/jni/medialibrary.cpp                  | 39 ++++++++++++++++++++++
 .../org/videolan/medialibrary/Medialibrary.java    | 15 +++++++++
 4 files changed, 76 insertions(+)

diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index edbf689..e557b97 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -68,6 +68,12 @@ AndroidMediaLibrary::addDevice(std::string uuid, std::string path, bool removabl
     p_DeviceListerCb->onDevicePlugged(uuid, path);
 }
 
+std::vector<std::tuple<std::string, std::string, bool>>
+AndroidMediaLibrary::devices()
+{
+    return p_lister->devices();
+}
+
 bool
 AndroidMediaLibrary::removeDevice(std::string uuid)
 {
@@ -89,6 +95,18 @@ AndroidMediaLibrary::discover(const std::string& libraryPath)
     p_ml->discover(libraryPath);
 }
 
+void
+AndroidMediaLibrary::removeEntryPoint(const std::string& entryPoint)
+{
+    p_ml->removeEntryPoint(entryPoint);
+}
+
+std::vector<medialibrary::FolderPtr>
+AndroidMediaLibrary::entryPoints()
+{
+    return p_ml->entryPoints();
+}
+
 bool
 AndroidMediaLibrary::isWorking()
 {
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index d91224f..2c7f5e6 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -16,6 +16,7 @@
 #include <medialibrary/IArtist.h>
 #include <medialibrary/IGenre.h>
 #include <medialibrary/IPlaylist.h>
+#include <medialibrary/IFolder.h>
 #include <medialibrary/Types.h>
 #include <medialibrary/IDeviceLister.h>
 #include <medialibrary/IMedia.h>
@@ -29,9 +30,12 @@ public:
 
     void initML(const std::string& dbPath, const std::string& thumbsPath);
     void addDevice(std::string uuid, std::string path, bool removable);
+    std::vector<std::tuple<std::string, std::string, bool>> devices();
     bool removeDevice(std::string uuid);
     void banFolder(const std::string& path);
     void discover(const std::string&);
+    void removeEntryPoint(const std::string& entryPoint);
+    std::vector<medialibrary::FolderPtr> entryPoints();
     bool isWorking();
     void setMediaUpdatedCbFlag(int flags);
     void setMediaAddedCbFlag(int flags);
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index edd62f4..60b9334 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -64,6 +64,20 @@ void addDevice(JNIEnv* env, jobject thiz, jstring uuid, jstring storagePath, jbo
     env->ReleaseStringUTFChars(storagePath, path);
 }
 
+jobjectArray
+devices(JNIEnv* env, jobject thiz)
+{
+    AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
+    auto devices = aml->devices();
+    jobjectArray deviceRefs = (jobjectArray) env->NewObjectArray(devices.size(), env->FindClass("java/lang/String"), NULL);
+    int index = -1;
+    for(auto device : devices) {
+        std::string path = std::get<1>(device);
+        env->SetObjectArrayElement(deviceRefs, ++index, env->NewStringUTF(path.c_str()));
+    }
+    return deviceRefs;
+}
+
 void
 discover(JNIEnv* env, jobject thiz, jstring storagePath)
 {
@@ -73,6 +87,28 @@ discover(JNIEnv* env, jobject thiz, jstring storagePath)
     env->ReleaseStringUTFChars(storagePath, path);
 }
 
+void
+removeEntryPoint(JNIEnv* env, jobject thiz, jstring storagePath)
+{
+    AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
+    const char *path = env->GetStringUTFChars(storagePath, JNI_FALSE);
+    aml->removeEntryPoint(path);
+    env->ReleaseStringUTFChars(storagePath, path);
+}
+
+jobjectArray
+entryPoints(JNIEnv* env, jobject thiz)
+{
+    AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
+    std::vector<medialibrary::FolderPtr> entryPoints = aml->entryPoints();
+    jobjectArray mediaRefs = (jobjectArray) env->NewObjectArray(entryPoints.size(), env->FindClass("java/lang/String"), NULL);
+    int index = -1;
+    for(medialibrary::FolderPtr const& entrypoint : entryPoints) {
+        env->SetObjectArrayElement(mediaRefs, ++index, env->NewStringUTF(entrypoint->path().c_str()));
+    }
+    return mediaRefs;
+}
+
 jboolean
 removeDevice(JNIEnv* env, jobject thiz, jstring uuid)
 {
@@ -515,7 +551,10 @@ static JNINativeMethod methods[] = {
     {"nativeInit", "(Ljava/lang/String;Ljava/lang/String;)V", (void*)init },
     {"nativeRelease", "()V", (void*)release },
     {"nativeAddDevice", "(Ljava/lang/String;Ljava/lang/String;Z)V", (void*)addDevice },
+    {"nativeDevices", "()[Ljava/lang/String;", (void*)devices },
     {"nativeDiscover", "(Ljava/lang/String;)V", (void*)discover },
+    {"nativeRemoveEntryPoint", "(Ljava/lang/String;)V", (void*)removeEntryPoint },
+    {"nativeEntryPoints", "()[Ljava/lang/String;", (void*)entryPoints },
     {"nativeRemoveDevice", "(Ljava/lang/String;)Z", (void*)removeDevice },
     {"nativeBanFolder", "(Ljava/lang/String;)V", (void*)banFolder },
     {"nativeLastMediaPlayed", "()[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)lastMediaPLayed },
diff --git a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
index f74b7ef..a26b47e 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -90,6 +90,10 @@ public class Medialibrary {
         if (mIsInitiated)
             nativeBanFolder(path);
     }
+
+    public String[] getDevices() {
+        return nativeDevices();
+    }
     public void addDevice(String uuid, String path, boolean removable) {
         nativeAddDevice(uuid, path, removable);
         for (String folder : banList)
@@ -100,6 +104,14 @@ public class Medialibrary {
         nativeDiscover(path);
     }
 
+    public void removeFolder(String path) {
+        nativeRemoveEntryPoint(path);
+    }
+
+    public String[] getFoldersList() {
+        return nativeEntryPoints();
+    }
+
     public boolean removeDevice(String uuid) {
         return nativeRemoveDevice(uuid);
     }
@@ -379,7 +391,10 @@ public class Medialibrary {
     private native void nativeRelease();
     private native void nativeBanFolder(String path);
     private native void nativeAddDevice(String uuid, String path, boolean removable);
+    private native String[] nativeDevices();
     private native void nativeDiscover(String path);
+    private native void nativeRemoveEntryPoint(String path);
+    private native String[] nativeEntryPoints();
     private native boolean nativeRemoveDevice(String uuid);
     private native MediaWrapper[] nativeLastMediaPlayed();
     private native MediaWrapper nativeGetMedia(long id);



More information about the Android mailing list