[Android] [PATCH 03/14] libvlc: move Extensions in a specific class

Thomas Guillem thomas at gllm.fr
Fri Jan 16 17:12:03 CET 2015


---
 libvlc/src/org/videolan/libvlc/Media.java          | 43 ++-------------
 .../src/org/videolan/libvlc/util/Extensions.java   | 62 ++++++++++++++++++++++
 vlc-android/src/org/videolan/vlc/MediaLibrary.java |  5 +-
 .../src/org/videolan/vlc/gui/DirectoryAdapter.java |  5 +-
 .../videolan/vlc/gui/video/MediaInfoFragment.java  |  3 +-
 5 files changed, 74 insertions(+), 44 deletions(-)
 create mode 100644 libvlc/src/org/videolan/libvlc/util/Extensions.java

diff --git a/libvlc/src/org/videolan/libvlc/Media.java b/libvlc/src/org/videolan/libvlc/Media.java
index 62ba1e5..27fd804 100644
--- a/libvlc/src/org/videolan/libvlc/Media.java
+++ b/libvlc/src/org/videolan/libvlc/Media.java
@@ -20,9 +20,10 @@
 
 package org.videolan.libvlc;
 
-import java.util.HashSet;
 import java.util.Locale;
 
+import org.videolan.libvlc.util.Extensions;
+
 import android.graphics.Bitmap;
 import android.os.Parcel;
 import android.os.Parcelable;
@@ -32,42 +33,6 @@ import android.util.Log;
 public class Media implements Parcelable {
     public final static String TAG = "VLC/LibVLC/Media";
 
-    public final static HashSet<String> VIDEO_EXTENSIONS;
-    public final static HashSet<String> AUDIO_EXTENSIONS;
-    public final static HashSet<String> SUBTITLES_EXTENSIONS;
-
-    static {
-        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",
-                ".mpeg1", ".mpeg2", ".mpeg4", ".mpg", ".mpv2", ".mts", ".mtv", ".mxf", ".mxg",
-                ".nsv", ".nut", ".nuv", ".ogm", ".ogv", ".ogx", ".ps", ".rec", ".rm", ".rmvb",
-                ".tod", ".ts", ".tts", ".vob", ".vro", ".webm", ".wm", ".wmv", ".wtv", ".xesc" };
-
-        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" };
-
-        final String[] subtitles_extensions = {
-                "idx", "sub",  "srt", "ssa", "ass",  "smi", "utf", "utf8", "utf-8",
-                "rt",   "aqt", "txt", "usf", "jss",  "cdg", "psb", "mpsub","mpl2",
-                "pjs", "dks", "stl", "vtt" };
-
-        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);
-        SUBTITLES_EXTENSIONS = new HashSet<String>();
-        for (String item : subtitles_extensions)
-            SUBTITLES_EXTENSIONS.add(item);
-    }
-
     public final static int TYPE_ALL = -1;
     public final static int TYPE_VIDEO = 0;
     public final static int TYPE_AUDIO = 1;
@@ -191,9 +156,9 @@ public class Media implements Parcelable {
             int dotIndex = mLocation.lastIndexOf(".");
             if (dotIndex != -1) {
                 String fileExt = mLocation.substring(dotIndex).toLowerCase(Locale.ENGLISH);
-                if( Media.VIDEO_EXTENSIONS.contains(fileExt) ) {
+                if( Extensions.VIDEO.contains(fileExt) ) {
                     mType = TYPE_VIDEO;
-                } else if (Media.AUDIO_EXTENSIONS.contains(fileExt)) {
+                } else if (Extensions.AUDIO.contains(fileExt)) {
                     mType = TYPE_AUDIO;
                 }
             }
diff --git a/libvlc/src/org/videolan/libvlc/util/Extensions.java b/libvlc/src/org/videolan/libvlc/util/Extensions.java
new file mode 100644
index 0000000..b1f9605
--- /dev/null
+++ b/libvlc/src/org/videolan/libvlc/util/Extensions.java
@@ -0,0 +1,62 @@
+/*****************************************************************************
+ * Extensions.java
+ *****************************************************************************
+ * Copyright © 2015 VLC authors, VideoLAN and VideoLabs
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+package org.videolan.libvlc.util;
+
+import java.util.HashSet;
+
+public class Extensions {
+
+    public final static HashSet<String> VIDEO;
+    public final static HashSet<String> AUDIO;
+    public final static HashSet<String> SUBTITLES;
+
+    static {
+        final String[] videoExtensions = {
+                ".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",
+                ".mpeg1", ".mpeg2", ".mpeg4", ".mpg", ".mpv2", ".mts", ".mtv", ".mxf", ".mxg",
+                ".nsv", ".nut", ".nuv", ".ogm", ".ogv", ".ogx", ".ps", ".rec", ".rm", ".rmvb",
+                ".tod", ".ts", ".tts", ".vob", ".vro", ".webm", ".wm", ".wmv", ".wtv", ".xesc" };
+
+        final String[] audioExtensions = {
+                ".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" };
+
+        final String[] subtitlesExtensions = {
+                "idx", "sub",  "srt", "ssa", "ass",  "smi", "utf", "utf8", "utf-8",
+                "rt",   "aqt", "txt", "usf", "jss",  "cdg", "psb", "mpsub","mpl2",
+                "pjs", "dks", "stl", "vtt" };
+
+        VIDEO = new HashSet<String>();
+        for (String item : videoExtensions)
+            VIDEO.add(item);
+        AUDIO = new HashSet<String>();
+        for (String item : audioExtensions)
+            AUDIO.add(item);
+        SUBTITLES = new HashSet<String>();
+        for (String item : subtitlesExtensions)
+            SUBTITLES.add(item);
+    }
+}
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/MediaLibrary.java b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
index 15c8ad3..34c29f6 100644
--- a/vlc-android/src/org/videolan/vlc/MediaLibrary.java
+++ b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
@@ -36,6 +36,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
 import org.videolan.libvlc.LibVLC;
 import org.videolan.libvlc.LibVlcException;
 import org.videolan.libvlc.Media;
+import org.videolan.libvlc.util.Extensions;
 import org.videolan.vlc.gui.MainActivity;
 import org.videolan.vlc.util.AndroidDevices;
 import org.videolan.vlc.util.Util;
@@ -396,8 +397,8 @@ public class MediaLibrary {
                     int dotIndex = fileName.lastIndexOf(".");
                     if (dotIndex != -1) {
                         String fileExt = fileName.substring(dotIndex);
-                        accepted = Media.AUDIO_EXTENSIONS.contains(fileExt) ||
-                                   Media.VIDEO_EXTENSIONS.contains(fileExt);
+                        accepted = Extensions.AUDIO.contains(fileExt) ||
+                                   Extensions.VIDEO.contains(fileExt);
                     }
                 }
             }
diff --git a/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java b/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
index a499db8..a1645fd 100644
--- a/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
@@ -30,6 +30,7 @@ import java.util.regex.Pattern;
 
 import org.videolan.libvlc.LibVLC;
 import org.videolan.libvlc.Media;
+import org.videolan.libvlc.util.Extensions;
 import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.util.AndroidDevices;
@@ -59,14 +60,14 @@ public class DirectoryAdapter extends BaseAdapter {
         final StringBuilder sb = new StringBuilder();
         sb.append(".+(\\.)((?i)(");
         boolean first = true;
-        for (String ext : Media.VIDEO_EXTENSIONS) {
+        for (String ext : Extensions.VIDEO) {
             if (!first)
                 sb.append('|');
             else
                 first = false;
             sb.append(ext.substring(1));
         }
-        for (String ext : Media.AUDIO_EXTENSIONS) {
+        for (String ext : Extensions.AUDIO) {
             sb.append('|');
             sb.append(ext.substring(1));
         }
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java
index f2d97ed..8b2ca81 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java
@@ -28,6 +28,7 @@ import org.videolan.libvlc.LibVlcException;
 import org.videolan.libvlc.LibVlcUtil;
 import org.videolan.libvlc.Media;
 import org.videolan.libvlc.TrackInfo;
+import org.videolan.libvlc.util.Extensions;
 import org.videolan.vlc.MediaLibrary;
 import org.videolan.vlc.R;
 import org.videolan.vlc.gui.MainActivity;
@@ -173,7 +174,7 @@ public class MediaInfoFragment extends ListFragment {
         for (int i = 0; i<files.length ; ++i){
             filename = Uri.decode(files[i]);
             extension = filename.substring(filename.lastIndexOf('.')+1);
-            if (!Media.SUBTITLES_EXTENSIONS.contains(extension))
+            if (!Extensions.SUBTITLES.contains(extension))
                 continue;
             if (filename.startsWith(videoName)) {
                 mHandler.obtainMessage(SHOW_SUBTITLES).sendToTarget();
-- 
2.1.3



More information about the Android mailing list