[Android] Check extension on filename instead of media title

Geoffrey Métais git at videolan.org
Tue Aug 9 18:29:49 CEST 2016


vlc-android | branch: 2.0.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Aug  9 17:28:49 2016 +0200| [cb5c7ebf2778fe2cac85b928ced695e82f73ea12] | committer: Geoffrey Métais

Check extension on filename instead of media title

(cherry picked from commit 90f0eb3c6cd0c492a0b4a56bee48149d28fff819)

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

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

diff --git a/vlc-android/src/org/videolan/vlc/media/MediaWrapper.java b/vlc-android/src/org/videolan/vlc/media/MediaWrapper.java
index b809500..90efbcd 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaWrapper.java
+++ b/vlc-android/src/org/videolan/vlc/media/MediaWrapper.java
@@ -161,22 +161,17 @@ public class MediaWrapper implements Parcelable {
         if (mType != TYPE_ALL)
             return;
 
-        String fileExt = null;
-        int dotIndex = mTitle != null ? mTitle.lastIndexOf(".") : -1;
-
-        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);
-            dotIndex = location.lastIndexOf(".");
-            if (dotIndex != -1)
-                fileExt = location.substring(dotIndex).toLowerCase(Locale.ENGLISH);
-        }
+        String fileExt = null, filename = mUri.getLastPathSegment();
+        if (filename == null)
+            return;
+        final int index = filename.indexOf('?');
+        if (index != -1)
+            filename = filename.substring(0, index);
+
+        index = filename.lastIndexOf(".");
+
+        if (index != -1)
+            fileExt = filename.substring(index).toLowerCase(Locale.ENGLISH);
 
         if (!TextUtils.isEmpty(fileExt)) {
             if (Extensions.VIDEO.contains(fileExt)) {



More information about the Android mailing list