[Android] Split medialibrary instanciation & initilization

Geoffrey Métais git at videolan.org
Fri Dec 23 11:44:29 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Dec 23 11:43:02 2016 +0100| [c2cd8223fc92a28fadd930571ad18850d09751c7] | committer: Geoffrey Métais

Split medialibrary instanciation & initilization

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

 medialibrary/jni/medialibrary.cpp                            | 10 ++++++++--
 medialibrary/src/org/videolan/medialibrary/Medialibrary.java |  7 +++++--
 vlc-android/src/org/videolan/vlc/VLCApplication.java         |  9 +++++++--
 3 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 74d18cf..4e71617 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -23,13 +23,18 @@ static void
 MediaLibrary_setInstance(JNIEnv *env, jobject thiz, AndroidMediaLibrary *p_obj);
 
 void
+setup(JNIEnv* env, jobject thiz) {
+    AndroidMediaLibrary *aml = new  AndroidMediaLibrary(myVm, &ml_fields, thiz);
+    MediaLibrary_setInstance(env, thiz, aml);
+}
+
+void
 init(JNIEnv* env, jobject thiz, jstring dbPath, jstring thumbsPath)
 {
     const char *db_utfchars = env->GetStringUTFChars(dbPath, JNI_FALSE);
     const char *thumbs_utfchars = env->GetStringUTFChars(thumbsPath, JNI_FALSE);
     const std::string stringDbPath(db_utfchars), stringThumbsPath(thumbs_utfchars);
-    AndroidMediaLibrary *aml = new  AndroidMediaLibrary(myVm, &ml_fields, thiz);
-    MediaLibrary_setInstance(env, thiz, aml);
+    AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
     aml->initML(stringDbPath, stringThumbsPath);
     env->ReleaseStringUTFChars(dbPath, db_utfchars);
     env->ReleaseStringUTFChars(thumbsPath, thumbs_utfchars);
@@ -580,6 +585,7 @@ playlistDelete(JNIEnv* env, jobject thiz, jobject medialibrary, jlong playlistId
   * JNI stuff
   */
 static JNINativeMethod methods[] = {
+    {"nativeSetup", "()V", (void*)setup },
     {"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 },
diff --git a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
index 4ca53ec..5958cfd 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -76,6 +76,10 @@ public class Medialibrary {
         System.loadLibrary("mla");
     }
 
+    public void setup() {
+        nativeSetup();
+    }
+
     public void init(Context context) {
         nativeInit(context.getCacheDir()+"/vlc_media.db", context.getExternalFilesDir(null).getAbsolutePath()+"/thumbs");
         mIsInitiated = true;
@@ -92,8 +96,6 @@ public class Medialibrary {
 
     public void addDevice(String uuid, String path, boolean removable) {
         nativeAddDevice(uuid, path, removable);
-        for (String folder : banList)
-            nativeBanFolder(path+folder);
     }
 
     public void discover(String path) {
@@ -397,6 +399,7 @@ public class Medialibrary {
 
 
     // Native methods
+    private native void nativeSetup();
     private native void nativeInit(String dbPath, String thumbsPath);
     private native void nativeRelease();
     private native void nativeBanFolder(String path);
diff --git a/vlc-android/src/org/videolan/vlc/VLCApplication.java b/vlc-android/src/org/videolan/vlc/VLCApplication.java
index d9fa2df..50848ce 100644
--- a/vlc-android/src/org/videolan/vlc/VLCApplication.java
+++ b/vlc-android/src/org/videolan/vlc/VLCApplication.java
@@ -231,9 +231,14 @@ public class VLCApplication extends Application {
     }
 
     public static void setupMedialibrary(final Medialibrary ml) {
-        ml.init(getAppContext());
-        for (String storage : AndroidDevices.getMediaDirectories())
+        ml.setup();
+        String[] storages = AndroidDevices.getMediaDirectories();
+        for (String storage : storages)
             ml.addDevice(storage, storage, TextUtils.equals(storage, AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY));
+        ml.init(getAppContext());
+        for (String storage : storages)
+            for (String folder : Medialibrary.banList)
+                ml.banFolder(storage+folder);
         if (ml.getFoldersList().length == 0) {
             ml.discover(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath());
             ml.discover(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getPath());



More information about the Android mailing list