[Android] Add defineType() in MediaWrapper

Geoffrey Métais git at videolan.org
Mon Dec 21 17:21:50 CET 2015


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Dec 10 14:37:05 2015 +0100| [8a3d8ffed4be93328222e15778b63ef657b56f7d] | committer: Geoffrey Métais

Add defineType() in MediaWrapper

Allows to auto-detect type according to file name or location

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

 .../src/org/videolan/vlc/media/MediaWrapper.java   | 40 +++++++++++++++-------
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/media/MediaWrapper.java b/vlc-android/src/org/videolan/vlc/media/MediaWrapper.java
index 0b1a7b1..950b666 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaWrapper.java
+++ b/vlc-android/src/org/videolan/vlc/media/MediaWrapper.java
@@ -141,26 +141,39 @@ public class MediaWrapper implements Parcelable {
             if (mType == TYPE_ALL && media.getType() == Media.Type.Directory)
                 mType = TYPE_DIR;
         }
+        defineType();
+    }
+
+    public void defineType() {
+        if (mType != TYPE_ALL)
+            return;
+
+        String fileExt = null;
+        int dotIndex = mTitle != null ? mTitle.lastIndexOf(".") : -1;
 
-        if (mType == TYPE_ALL) {
+        if (dotIndex != -1) {
+            fileExt = mTitle.substring(dotIndex).toLowerCase(Locale.ENGLISH);
+        } else {
             final int index = mUri.toString().indexOf('?');
             String location;
             if (index == -1)
                 location = mUri.toString();
             else
                 location = mUri.toString().substring(0, index);
-            int dotIndex = location.lastIndexOf(".");
-            if (dotIndex != -1) {
-                String fileExt = location.substring(dotIndex).toLowerCase(Locale.ENGLISH);
-                if( Extensions.VIDEO.contains(fileExt) ) {
-                    mType = TYPE_VIDEO;
-                } else if (Extensions.AUDIO.contains(fileExt)) {
-                    mType = TYPE_AUDIO;
-                } else if (Extensions.SUBTITLES.contains(fileExt)) {
-                    mType = TYPE_SUBTITLE;
-                } else if (Extensions.PLAYLIST.contains(fileExt)) {
-                    mType = TYPE_PLAYLIST;
-                }
+            dotIndex = location.lastIndexOf(".");
+            if (dotIndex != -1)
+                fileExt = location.substring(dotIndex).toLowerCase(Locale.ENGLISH);
+        }
+
+        if (!TextUtils.isEmpty(fileExt)) {
+            if (Extensions.VIDEO.contains(fileExt)) {
+                mType = TYPE_VIDEO;
+            } else if (Extensions.AUDIO.contains(fileExt)) {
+                mType = TYPE_AUDIO;
+            } else if (Extensions.SUBTITLES.contains(fileExt)) {
+                mType = TYPE_SUBTITLE;
+            } else if (Extensions.PLAYLIST.contains(fileExt)) {
+                mType = TYPE_PLAYLIST;
             }
         }
     }
@@ -328,6 +341,7 @@ public class MediaWrapper implements Parcelable {
 
     public void setTitle(String title){
         mTitle = title;
+        defineType();
     }
 
     public void setArtist(String artist){



More information about the Android mailing list