[Android] Initialize method returns success

Geoffrey Métais git at videolan.org
Fri Dec 23 16:38:31 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Dec 23 14:23:22 2016 +0100| [10d5088db21342a2b2c5074e626271ce8a9b29ec] | committer: Geoffrey Métais

Initialize method returns success

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

 medialibrary/jni/AndroidMediaLibrary.cpp           |  4 ++--
 medialibrary/jni/AndroidMediaLibrary.h             |  2 +-
 medialibrary/jni/medialibrary.cpp                  |  8 ++++----
 .../src/org/videolan/vlc/VLCApplication.java       | 23 +++++++++++-----------
 4 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index 5063c3e..976bcc0 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -55,10 +55,10 @@ AndroidMediaLibrary::~AndroidMediaLibrary()
     delete p_ml;
 }
 
-void
+bool
 AndroidMediaLibrary::initML(const std::string& dbPath, const std::string& thumbsPath)
 {
-    p_ml->initialize(dbPath, thumbsPath, this);
+    return p_ml->initialize(dbPath, thumbsPath, this);
 }
 
 void
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index 6b3d3c2..eb689a3 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -29,7 +29,7 @@ public:
     AndroidMediaLibrary(JavaVM *vm, fields *ref_fields, jobject thiz);
     ~AndroidMediaLibrary();
 
-    void initML(const std::string& dbPath, const std::string& thumbsPath);
+    bool initML(const std::string& dbPath, const std::string& thumbsPath);
     void addDevice(const std::string& uuid, const std::string& path, bool removable);
     std::vector<std::tuple<std::string, std::string, bool>> devices();
     bool removeDevice(const std::string& uuid);
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 4e71617..46eb79e 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -28,17 +28,17 @@ setup(JNIEnv* env, jobject thiz) {
     MediaLibrary_setInstance(env, thiz, aml);
 }
 
-void
+jboolean
 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 = MediaLibrary_getInstance(env, thiz);
-    aml->initML(stringDbPath, stringThumbsPath);
+    m_IsInitialized = aml->initML(stringDbPath, stringThumbsPath);
     env->ReleaseStringUTFChars(dbPath, db_utfchars);
     env->ReleaseStringUTFChars(thumbsPath, thumbs_utfchars);
-    m_IsInitialized = true;
+    return m_IsInitialized;
 }
 
 void release(JNIEnv* env, jobject thiz)
@@ -586,7 +586,7 @@ playlistDelete(JNIEnv* env, jobject thiz, jobject medialibrary, jlong playlistId
   */
 static JNINativeMethod methods[] = {
     {"nativeSetup", "()V", (void*)setup },
-    {"nativeInit", "(Ljava/lang/String;Ljava/lang/String;)V", (void*)init },
+    {"nativeInit", "(Ljava/lang/String;Ljava/lang/String;)Z", (void*)init },
     {"nativeRelease", "()V", (void*)release },
     {"nativeAddDevice", "(Ljava/lang/String;Ljava/lang/String;Z)V", (void*)addDevice },
     {"nativeDevices", "()[Ljava/lang/String;", (void*)devices },
diff --git a/vlc-android/src/org/videolan/vlc/VLCApplication.java b/vlc-android/src/org/videolan/vlc/VLCApplication.java
index 50848ce..a9325fe 100644
--- a/vlc-android/src/org/videolan/vlc/VLCApplication.java
+++ b/vlc-android/src/org/videolan/vlc/VLCApplication.java
@@ -235,17 +235,18 @@ public class VLCApplication extends Application {
         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());
-            ml.discover(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).getPath());
-            ml.discover(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PODCASTS).getPath());
-            for (String externalStorage : AndroidDevices.getExternalStorageDirectories())
-                ml.discover(externalStorage);
+        if (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());
+                ml.discover(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).getPath());
+                ml.discover(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PODCASTS).getPath());
+                for (String externalStorage : AndroidDevices.getExternalStorageDirectories())
+                    ml.discover(externalStorage);
+            }
         }
     }
 }



More information about the Android mailing list