[Android] Fix ML encoding

Geoffrey Métais git at videolan.org
Wed Jan 11 15:21:13 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Jan 11 15:20:35 2017 +0100| [1d70d4e8f5a936e704d78efad539d8a2e0be86f1] | committer: Geoffrey Métais

Fix ML encoding

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

 .../org/videolan/medialibrary/Medialibrary.java    | 23 ++++++++++++++--------
 .../src/org/videolan/medialibrary/Tools.java       | 14 ++++++++-----
 .../vlc/gui/browser/BaseBrowserFragment.java       |  2 +-
 .../vlc/gui/dialogs/SavePlaylistDialog.java        |  2 +-
 .../videolan/vlc/gui/helpers/AsyncImageLoader.java |  2 +-
 .../vlc/gui/video/VideoPlayerActivity.java         |  6 +++---
 6 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
index dc3140d..2e06a42 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -10,6 +10,7 @@ import android.support.v4.content.ContextCompat;
 import android.text.TextUtils;
 import android.util.Log;
 
+import org.videolan.libvlc.util.VLCUtil;
 import org.videolan.medialibrary.interfaces.DevicesDiscoveryCb;
 import org.videolan.medialibrary.interfaces.MediaAddedCb;
 import org.videolan.medialibrary.interfaces.MediaUpdatedCb;
@@ -70,7 +71,7 @@ public class Medialibrary {
 
     public void banFolder(String path) {
         if (mIsInitiated && new File(path).exists())
-            nativeBanFolder(Tools.encodeMrl(path));
+            nativeBanFolder(Tools.encodeVLCMrl(path));
     }
 
     public String[] getDevices() {
@@ -78,15 +79,15 @@ public class Medialibrary {
     }
 
     public void addDevice(String uuid, String path, boolean removable) {
-        nativeAddDevice(uuid, Tools.encodeMrl(path), removable);
+        nativeAddDevice(uuid, Tools.encodeVLCMrl(path), removable);
     }
 
     public void discover(String path) {
-        nativeDiscover(Tools.encodeMrl(path));
+        nativeDiscover(Tools.encodeVLCMrl(path));
     }
 
     public void removeFolder(String path) {
-        nativeRemoveEntryPoint(Tools.encodeMrl(path));
+        nativeRemoveEntryPoint(Tools.encodeVLCMrl(path));
     }
 
     public String[] getFoldersList() {
@@ -201,12 +202,18 @@ public class Medialibrary {
     public MediaWrapper getMedia(long id) {
         return mIsInitiated ? nativeGetMedia(id) : null;
     }
+
+    public MediaWrapper getMedia(Uri uri) {
+        return mIsInitiated ? nativeGetMediaFromMrl(VLCUtil.locationFromUri(uri)) : null;
+    }
+
     public MediaWrapper getMedia(String mrl) {
-        return mIsInitiated ? nativeGetMediaFromMrl(Tools.encodeMrl(mrl)) : null;
+        Log.d(TAG, "getMedia: "+Tools.encodeVLCMrl(mrl));
+        return mIsInitiated ? nativeGetMediaFromMrl(Tools.encodeVLCMrl(mrl)) : null;
     }
 
     public MediaWrapper addMedia(String mrl) {
-        return mIsInitiated ? nativeAddMedia(Tools.encodeMrl(mrl)) : null;
+        return mIsInitiated ? nativeAddMedia(Tools.encodeVLCMrl(mrl)) : null;
     }
 
     public long getId() {
@@ -230,11 +237,11 @@ public class Medialibrary {
             return false;
         if (mw != null && mw.getId() == 0) {
             Uri uri = mw.getUri();
-            mw = nativeGetMediaFromMrl(uri.getPath());
+            mw = getMedia(uri);
             if (mw == null  && TextUtils.equals("file", uri.getScheme()) &&
                     uri.getPath() != null && uri.getPath().startsWith("/sdcard")) {
                 uri = Tools.convertLocalUri(uri);
-                mw = nativeGetMediaFromMrl(uri.getPath());
+                mw = getMedia(uri);
             }
         }
         return mw != null && nativeUpdateProgress(mw.getId(), time);
diff --git a/medialibrary/src/org/videolan/medialibrary/Tools.java b/medialibrary/src/org/videolan/medialibrary/Tools.java
index 61b83fa..a6ede01 100644
--- a/medialibrary/src/org/videolan/medialibrary/Tools.java
+++ b/medialibrary/src/org/videolan/medialibrary/Tools.java
@@ -124,11 +124,15 @@ public class Tools {
         return sb.toString();
     }
 
-    public static String encodeMrl(String mrl) {
-        sb.setLength(0);
-        if (mrl.startsWith("/"))
-            sb.append("file://");
+    public static Uri decodeMrl(String mrl) {
         sb.append(VLCUtil.UriFromMrl(mrl).toString());
-        return sb.toString();
+        return VLCUtil.UriFromMrl(mrl);
+    }
+
+    public static String encodeVLCMrl(String mrl) {
+        if (mrl.startsWith("/"))
+            mrl = "file://"+mrl;
+        return VLCUtil.locationFromUri(Uri.parse(mrl));
+
     }
 }
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
index 77466d8..9a7c33d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -421,7 +421,7 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
         if (! (mAdapter.getItem(position) instanceof MediaWrapper))
             return super.onContextItemSelected(item);
         Uri uri = ((MediaWrapper) mAdapter.getItem(position)).getUri();
-        MediaWrapper mwFromMl = "file".equals(uri.getScheme()) ? mMediaLibrary.getMedia(uri.toString()) : null;
+        MediaWrapper mwFromMl = "file".equals(uri.getScheme()) ? mMediaLibrary.getMedia(uri) : null;
         final MediaWrapper mw = mwFromMl != null ? mwFromMl : (MediaWrapper) mAdapter.getItem(position);
         switch (id){
             case R.id.directory_view_play_all:
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java
index 26694ed..a708ca9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java
@@ -160,7 +160,7 @@ public class SavePlaylistDialog extends DialogFragment implements View.OnClickLi
                 for (MediaWrapper mw : tracks) {
                     long id = mw.getId();
                     if (id == 0) {
-                        MediaWrapper media = mMedialibrary.getMedia(mw.getLocation());
+                        MediaWrapper media = mMedialibrary.getMedia(mw.getUri());
                         if (media != null)
                             ids.add(media.getId());
                         else {
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/AsyncImageLoader.java b/vlc-android/src/org/videolan/vlc/gui/helpers/AsyncImageLoader.java
index c1c7b49..5442948 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/AsyncImageLoader.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/AsyncImageLoader.java
@@ -94,7 +94,7 @@ public class AsyncImageLoader {
             if (!isMedia && !(type == MediaWrapper.TYPE_DIR && "upnp".equals(uri.getScheme())))
                 return;
             if (item.getId() == 0L && (isMedia) && "file".equals(uri.getScheme())) {
-                MediaWrapper mw = VLCApplication.getMLInstance().getMedia(uri.toString());
+                MediaWrapper mw = VLCApplication.getMLInstance().getMedia(uri);
                 if (mw != null)
                     item = mw;
             }
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index 84cff96..9271f49 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -2893,7 +2893,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
         if (length == 0) {
             MediaWrapper media = mService.getCurrentMediaWrapper();
             if (media.getId() == 0)
-                media = VLCApplication.getMLInstance().getMedia(mUri.toString());
+                media = VLCApplication.getMLInstance().getMedia(mUri);
             if (media != null)
                 length = (int) media.getLength();
         }
@@ -3046,11 +3046,11 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
             MediaWrapper media;
             if (openedMedia == null || openedMedia.getId() <= 0L) {
                 Medialibrary ml = VLCApplication.getMLInstance();
-                media = ml.getMedia(mUri.toString());
+                media = ml.getMedia(mUri);
                 if (media == null && TextUtils.equals(mUri.getScheme(), "file") &&
                         mUri.getPath() != null && mUri.getPath().startsWith("/sdcard")) {
                     mUri = FileUtils.convertLocalUri(mUri);
-                    media = ml.getMedia(mUri.toString());
+                    media = ml.getMedia(mUri);
                 }
             } else
                 media = openedMedia;



More information about the Android mailing list