[Android] Update Medialibrary call to new API

Geoffrey Métais git at videolan.org
Wed Apr 19 14:46:01 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Apr 18 19:15:57 2017 +0200| [c6a6c9e8b15bf4866cc0df9f5c70dbdeef7cc01b] | committer: Geoffrey Métais

Update Medialibrary call to new API

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

 .../src/org/videolan/vlc/MediaParsingService.java  | 39 +++++++++++++---------
 1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.java b/vlc-android/src/org/videolan/vlc/MediaParsingService.java
index 12938df..7ff8679 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.java
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.java
@@ -26,6 +26,8 @@ import org.videolan.vlc.util.FileUtils;
 import org.videolan.vlc.util.Strings;
 
 import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
@@ -178,25 +180,32 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
                     mMedialibrary.setup();
                     if (mMedialibrary.init(MediaParsingService.this)) {
                         boolean shouldInit = !(new File(MediaParsingService.this.getCacheDir()+Medialibrary.VLC_MEDIA_DB_NAME).exists());
-                        String[] storages = AndroidDevices.getMediaDirectories();
-                        for (String storage : storages) {
-                            boolean isMainStorage = TextUtils.equals(storage, AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY);
-                            boolean isNew = mMedialibrary.addDevice(isMainStorage ? "main-storage" : FileUtils.getFileNameFromPath(storage), storage, !isMainStorage);
-                            if (!isMainStorage && isNew) {
-                                startActivity(new Intent(MediaParsingService.this, DialogActivity.class)
-                                        .setAction(DialogActivity.KEY_STORAGE)
-                                        .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
-                                        .putExtra(EXTRA_PATH, storage));
+                        List<String> devices = new ArrayList<>();
+                        devices.add(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY);
+                        devices.addAll(AndroidDevices.getExternalStorageDirectories());
+                        for (String device : devices) {
+                            boolean isMainStorage = TextUtils.equals(device, AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY);
+                            boolean isNew = mMedialibrary.addDevice(isMainStorage ? "main-storage" : FileUtils.getFileNameFromPath(device), device, !isMainStorage);
+                            if (isMainStorage) {
+                                if (shouldInit) {
+                                    for (String folder : Medialibrary.getBlackList())
+                                        mMedialibrary.banFolder(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY + folder);
+                                }
+                            } else if (isNew) {
+                                    startActivity(new Intent(MediaParsingService.this, DialogActivity.class)
+                                            .setAction(DialogActivity.KEY_STORAGE)
+                                            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+                                            .putExtra(EXTRA_PATH, device));
                             }
+
                         }
+                        mMedialibrary.start();
+                        for (String storage : AndroidDevices.getMediaDirectories())
+                            mMedialibrary.discover(storage);
                         LocalBroadcastManager.getInstance(MediaParsingService.this).sendBroadcast(new Intent(VLCApplication.ACTION_MEDIALIBRARY_READY));
-                        if (shouldInit) {
-                            for (String folder : Medialibrary.getBlackList())
-                                mMedialibrary.banFolder(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY + folder);
-                            mMedialibrary.discover(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY);
-                        } else if (upgrade) {
+                        if (upgrade) {
                             mMedialibrary.forceParserRetry();
-                        } else
+                        } else if (!shouldInit)
                             reload();
                     }
                 }



More information about the Android mailing list