[Android] Workaround issue with listFiles...

Jean-Baptiste Kempf git at videolan.org
Fri Sep 28 11:43:11 CEST 2012


vlc-ports/android | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Fri Sep 28 11:42:28 2012 +0200| [721da7a2097a4f7f6a98d614ceeeb17ed403df8a] | committer: Jean-Baptiste Kempf

Workaround issue with listFiles...

I wonder how can this happen...

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=721da7a2097a4f7f6a98d614ceeeb17ed403df8a
---

 vlc-android/src/org/videolan/vlc/MediaLibrary.java |   18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/MediaLibrary.java b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
index 60448ec..d393d0e 100644
--- a/vlc-android/src/org/videolan/vlc/MediaLibrary.java
+++ b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
@@ -226,14 +226,20 @@ public class MediaLibrary {
                 }
 
                 // Filter the extensions and the folders
-                if ((f = dir.listFiles(mediaFileFilter)) != null) {
-                    for (File file : f) {
-                        if (file.isFile()) {
-                            mediaToScan.add(file);
-                        } else if (file.isDirectory()) {
-                            directories.push(file);
+                try { 
+                    if ((f = dir.listFiles(mediaFileFilter)) != null) {
+                        for (File file : f) {
+                            if (file.isFile()) {
+                                mediaToScan.add(file);
+                            } else if (file.isDirectory()) {
+                                directories.push(file);
+                            }
                         }
                     }
+                } catch (Exception e)
+                {
+                    // listFiles can fail in OutOfMemoryError, go to the next folder
+                    continue;
                 }
             }
 



More information about the Android mailing list