[Android] Add locationFromMrl method

Geoffrey Métais git at videolan.org
Fri May 26 11:15:19 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri May 26 10:19:38 2017 +0200| [59423e069dec2953c6a6023349c862baa0a48751] | committer: Geoffrey Métais

Add locationFromMrl method

Get rid of useless string -> Uri -> String conversion

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

 libvlc/src/org/videolan/libvlc/util/VLCUtil.java      | 11 ++++++++---
 medialibrary/src/org/videolan/medialibrary/Tools.java |  2 +-
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/libvlc/src/org/videolan/libvlc/util/VLCUtil.java b/libvlc/src/org/videolan/libvlc/util/VLCUtil.java
index 441bc2ef8..7eb6c8af2 100644
--- a/libvlc/src/org/videolan/libvlc/util/VLCUtil.java
+++ b/libvlc/src/org/videolan/libvlc/util/VLCUtil.java
@@ -25,6 +25,7 @@ import android.content.Context;
 import android.content.pm.ApplicationInfo;
 import android.net.Uri;
 import android.os.Build;
+import android.support.annotation.NonNull;
 import android.util.Log;
 
 import org.videolan.libvlc.LibVLC;
@@ -547,12 +548,16 @@ public class VLCUtil {
         return Uri.parse(sb.toString());
     }
 
+    public static String locationFromUri(@NonNull Uri uri) {
+        return locationFromMrl(uri.toString());
+    }
+
     /**
-     * VLC authorize only "-._~" in Mrl format, android Uri authorize "_-!.~'()*".
+     * VLC only acccepts "-._~" in Mrl format, android Uri accepts "_-!.~'()*".
      * Therefore, encode the characters authorized by Android Uri when creating a mrl from an Uri.
      */
-    public static String locationFromUri(Uri uri) {
-        final char array[] = uri.toString().toCharArray();
+    public static String locationFromMrl(@NonNull String mrl) {
+        final char[] array = mrl.toCharArray();
         final StringBuilder sb = new StringBuilder(array.length * 2);
 
         for (final char c : array) {
diff --git a/medialibrary/src/org/videolan/medialibrary/Tools.java b/medialibrary/src/org/videolan/medialibrary/Tools.java
index 6825f2cbd..8ef9b9adb 100644
--- a/medialibrary/src/org/videolan/medialibrary/Tools.java
+++ b/medialibrary/src/org/videolan/medialibrary/Tools.java
@@ -127,6 +127,6 @@ public class Tools {
     public static String encodeVLCMrl(String mrl) {
         if (mrl.startsWith("/"))
             mrl = "file://"+mrl;
-        return VLCUtil.locationFromUri(Uri.parse(mrl));
+        return VLCUtil.locationFromMrl(mrl);
     }
 }



More information about the Android mailing list