[Android] libvlc: move ext regex and folder blacklist outside libvlc
Thomas Guillem
git at videolan.org
Wed Dec 31 10:47:52 CET 2014
vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Dec 31 10:23:45 2014 +0100| [d5f55e56663aa0cb97b77284025dd19eb1a33807] | committer: Thomas Guillem
libvlc: move ext regex and folder blacklist outside libvlc
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=d5f55e56663aa0cb97b77284025dd19eb1a33807
---
libvlc/src/org/videolan/libvlc/Media.java | 35 ++------------------
vlc-android/src/org/videolan/vlc/MediaLibrary.java | 21 +++++++++++-
.../src/org/videolan/vlc/gui/BrowserActivity.java | 4 +--
.../src/org/videolan/vlc/gui/DirectoryAdapter.java | 18 +++++++++-
4 files changed, 41 insertions(+), 37 deletions(-)
diff --git a/libvlc/src/org/videolan/libvlc/Media.java b/libvlc/src/org/videolan/libvlc/Media.java
index 2875022..9423ab7 100644
--- a/libvlc/src/org/videolan/libvlc/Media.java
+++ b/libvlc/src/org/videolan/libvlc/Media.java
@@ -32,11 +32,9 @@ public class Media implements Comparable<Media> {
public final static HashSet<String> VIDEO_EXTENSIONS;
public final static HashSet<String> AUDIO_EXTENSIONS;
- public final static String EXTENSIONS_REGEX;
- public final static HashSet<String> FOLDER_BLACKLIST;
static {
- String[] video_extensions = {
+ final String[] video_extensions = {
".3g2", ".3gp", ".3gp2", ".3gpp", ".amv", ".asf", ".avi", ".divx", ".drc", ".dv",
".f4v", ".flv", ".gvi", ".gxf", ".ismv", ".iso", ".m1v", ".m2v", ".m2t", ".m2ts",
".m4v", ".mkv", ".mov", ".mp2", ".mp2v", ".mp4", ".mp4v", ".mpe", ".mpeg",
@@ -44,48 +42,19 @@ public class Media implements Comparable<Media> {
".nsv", ".nut", ".nuv", ".ogm", ".ogv", ".ogx", ".ps", ".rec", ".rm", ".rmvb",
".tod", ".ts", ".tts", ".vob", ".vro", ".webm", ".wm", ".wmv", ".wtv", ".xesc" };
- String[] audio_extensions = {
+ final String[] audio_extensions = {
".3ga", ".a52", ".aac", ".ac3", ".adt", ".adts", ".aif", ".aifc", ".aiff", ".amr",
".aob", ".ape", ".awb", ".caf", ".dts", ".flac", ".it", ".m4a", ".m4b", ".m4p",
".mid", ".mka", ".mlp", ".mod", ".mpa", ".mp1", ".mp2", ".mp3", ".mpc", ".mpga",
".oga", ".ogg", ".oma", ".opus", ".ra", ".ram", ".rmi", ".s3m", ".spx", ".tta",
".voc", ".vqf", ".w64", ".wav", ".wma", ".wv", ".xa", ".xm" };
- String[] folder_blacklist = {
- "/alarms",
- "/notifications",
- "/ringtones",
- "/media/alarms",
- "/media/notifications",
- "/media/ringtones",
- "/media/audio/alarms",
- "/media/audio/notifications",
- "/media/audio/ringtones",
- "/Android/data/" };
-
VIDEO_EXTENSIONS = new HashSet<String>();
for (String item : video_extensions)
VIDEO_EXTENSIONS.add(item);
AUDIO_EXTENSIONS = new HashSet<String>();
for (String item : audio_extensions)
AUDIO_EXTENSIONS.add(item);
-
- StringBuilder sb = new StringBuilder(115);
- sb.append(".+(\\.)((?i)(");
- sb.append(video_extensions[0].substring(1));
- for(int i = 1; i < video_extensions.length; i++) {
- sb.append('|');
- sb.append(video_extensions[i].substring(1));
- }
- for(int i = 0; i < audio_extensions.length; i++) {
- sb.append('|');
- sb.append(audio_extensions[i].substring(1));
- }
- sb.append("))");
- EXTENSIONS_REGEX = sb.toString();
- FOLDER_BLACKLIST = new HashSet<String>();
- for (String item : folder_blacklist)
- FOLDER_BLACKLIST.add(android.os.Environment.getExternalStorageDirectory().getPath() + item);
}
public final static int TYPE_ALL = -1;
diff --git a/vlc-android/src/org/videolan/vlc/MediaLibrary.java b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
index dce7540..15c8ad3 100644
--- a/vlc-android/src/org/videolan/vlc/MediaLibrary.java
+++ b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
@@ -61,6 +61,25 @@ public class MediaLibrary {
private boolean mRestart = false;
protected Thread mLoadingThread;
+ public final static HashSet<String> FOLDER_BLACKLIST;
+ static {
+ final String[] folder_blacklist = {
+ "/alarms",
+ "/notifications",
+ "/ringtones",
+ "/media/alarms",
+ "/media/notifications",
+ "/media/ringtones",
+ "/media/audio/alarms",
+ "/media/audio/notifications",
+ "/media/audio/ringtones",
+ "/Android/data/" };
+
+ FOLDER_BLACKLIST = new HashSet<String>();
+ for (String item : folder_blacklist)
+ FOLDER_BLACKLIST.add(android.os.Environment.getExternalStorageDirectory().getPath() + item);
+ }
+
private MediaLibrary() {
mInstance = this;
mItemList = new ArrayList<Media>();
@@ -370,7 +389,7 @@ public class MediaLibrary {
public boolean accept(File f) {
boolean accepted = false;
if (!f.isHidden()) {
- if (f.isDirectory() && !Media.FOLDER_BLACKLIST.contains(f.getPath().toLowerCase(Locale.ENGLISH))) {
+ if (f.isDirectory() && !FOLDER_BLACKLIST.contains(f.getPath().toLowerCase(Locale.ENGLISH))) {
accepted = true;
} else {
String fileName = f.getName().toLowerCase(Locale.ENGLISH);
diff --git a/vlc-android/src/org/videolan/vlc/gui/BrowserActivity.java b/vlc-android/src/org/videolan/vlc/gui/BrowserActivity.java
index 50d96a4..89983ae 100644
--- a/vlc-android/src/org/videolan/vlc/gui/BrowserActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/BrowserActivity.java
@@ -27,8 +27,8 @@ import java.util.Arrays;
import java.util.Locale;
import java.util.Stack;
-import org.videolan.libvlc.Media;
import org.videolan.vlc.MediaDatabase;
+import org.videolan.vlc.MediaLibrary;
import org.videolan.vlc.R;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.CustomDirectories;
@@ -284,7 +284,7 @@ public class BrowserActivity extends ListActivity {
@Override
public boolean accept(File f) {
- return f.isDirectory() && !Media.FOLDER_BLACKLIST.contains(f.getPath().toLowerCase(Locale.ENGLISH));
+ return f.isDirectory() && !MediaLibrary.FOLDER_BLACKLIST.contains(f.getPath().toLowerCase(Locale.ENGLISH));
}
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java b/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
index bd5ffbf..a499db8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
@@ -56,7 +56,23 @@ public class DirectoryAdapter extends BaseAdapter {
private ContextPopupMenuListener mContextPopupMenuListener;
public static boolean acceptedPath(String f) {
- return Pattern.compile(Media.EXTENSIONS_REGEX, Pattern.CASE_INSENSITIVE).matcher(f).matches();
+ final StringBuilder sb = new StringBuilder();
+ sb.append(".+(\\.)((?i)(");
+ boolean first = true;
+ for (String ext : Media.VIDEO_EXTENSIONS) {
+ if (!first)
+ sb.append('|');
+ else
+ first = false;
+ sb.append(ext.substring(1));
+ }
+ for (String ext : Media.AUDIO_EXTENSIONS) {
+ sb.append('|');
+ sb.append(ext.substring(1));
+ }
+ sb.append("))");
+
+ return Pattern.compile(sb.toString(), Pattern.CASE_INSENSITIVE).matcher(f).matches();
}
/**
More information about the Android
mailing list