[Android] Set DeviceLister later

Geoffrey Métais git at videolan.org
Mon Jan 2 16:55:01 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Jan  2 16:54:18 2017 +0100| [eb4b93e68e41fe6178b6425a019be8d49851697b] | committer: Geoffrey Métais

Set DeviceLister later

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

 medialibrary/jni/AndroidMediaLibrary.cpp | 5 +++--
 medialibrary/jni/AndroidMediaLibrary.h   | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index 1eb4b0d..81bc65f 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -29,7 +29,6 @@ AndroidMediaLibrary::AndroidMediaLibrary(JavaVM *vm, fields *ref_fields, jobject
     p_lister = std::make_shared<AndroidDeviceLister>();
     p_ml->setLogger( new AndroidMediaLibraryLogger );
     p_ml->setVerbosity(medialibrary::LogLevel::Info);
-    p_DeviceListerCb = p_ml->setDeviceLister(p_lister);
     pthread_once(&key_once, key_init);
     JNIEnv *env = getEnv();
     if (env == NULL)
@@ -58,6 +57,7 @@ AndroidMediaLibrary::~AndroidMediaLibrary()
 bool
 AndroidMediaLibrary::initML(const std::string& dbPath, const std::string& thumbsPath)
 {
+    p_DeviceListerCb = p_ml->setDeviceLister(p_lister);
     return p_ml->initialize(dbPath, thumbsPath, this);
 }
 
@@ -65,7 +65,8 @@ void
 AndroidMediaLibrary::addDevice(const std::string& uuid, const std::string& path, bool removable)
 {
     p_lister->addDevice(uuid, path, removable);
-    p_DeviceListerCb->onDevicePlugged(uuid, path);
+    if (p_DeviceListerCb != nullptr)
+        p_DeviceListerCb->onDevicePlugged(uuid, path);
 }
 
 std::vector<std::tuple<std::string, std::string, bool>>
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index 141dabb..45dfa73 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -114,7 +114,7 @@ private:
     fields *p_fields;
     medialibrary::IMediaLibrary* p_ml;
     std::shared_ptr<AndroidDeviceLister> p_lister;
-    medialibrary::IDeviceListerCb* p_DeviceListerCb;
+    medialibrary::IDeviceListerCb* p_DeviceListerCb = nullptr;
     std::string mainStorage = "";
     bool discoveryEnded = false;
     uint32_t m_nbDiscovery = 0, m_progress = 0, m_mediaAddedType = 0, m_mediaUpdatedType = 0;



More information about the Android mailing list