[Android] Add device to ML if needed on folder scan request

Geoffrey Métais git at videolan.org
Thu Apr 6 13:57:25 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Apr  6 13:29:15 2017 +0200| [b5625bffbcc13b272b37f363abfc660b8c4ca69f] | committer: Geoffrey Métais

Add device to ML if needed on folder scan request

Add external storage to Medialibrary if user wants to scan it (or a
subfolder) and it's not been added to Medialibrary yet

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

 .../src/org/videolan/vlc/MediaParsingService.java      | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.java b/vlc-android/src/org/videolan/vlc/MediaParsingService.java
index 103ca77..44cdb4b 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.java
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.java
@@ -124,13 +124,29 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
             mMedialibrary.addDevice(uuid, path, true);
         for (String folder : Medialibrary.getBlackList())
             mMedialibrary.banFolder(path + folder);
-        discover(path);
+        mMedialibrary.discover(path);
     }
 
     private void discover(String path) {
+        if (TextUtils.isEmpty(path))
+            return;
+        addDeviceIfNeeded(path);
         mMedialibrary.discover(path);
     }
 
+    private void addDeviceIfNeeded(String path) {
+        for (String devicePath : mMedialibrary.getDevices()) {
+            if (path.startsWith(devicePath))
+                return;
+        }
+        for (String storagePath : AndroidDevices.getExternalStorageDirectories()) {
+            if (path.startsWith(storagePath)) {
+                String uuid = FileUtils.getFileNameFromPath(path);
+                mMedialibrary.addDevice(uuid, path, true);
+            }
+        }
+    }
+
     private void reload() {
         if (mReload > 0)
             return;



More information about the Android mailing list