[Android] utils: Use more Uri
Thomas Guillem
git at videolan.org
Mon Jun 8 11:50:48 CEST 2015
vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri Jun 5 13:51:01 2015 +0200| [8d0e8b0ec1fa68843e35fd7110f6598879ed4d71] | committer: Thomas Guillem
utils: Use more Uri
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=8d0e8b0ec1fa68843e35fd7110f6598879ed4d71
---
.../src/org/videolan/libvlc/util/AndroidUtil.java | 27 ++++++++++++--------
vlc-android/src/org/videolan/vlc/MediaLibrary.java | 2 +-
.../src/org/videolan/vlc/gui/audio/AudioUtil.java | 4 +--
.../vlc/gui/video/VideoPlayerActivity.java | 4 +--
4 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/libvlc/src/org/videolan/libvlc/util/AndroidUtil.java b/libvlc/src/org/videolan/libvlc/util/AndroidUtil.java
index a024203..2b795c3 100644
--- a/libvlc/src/org/videolan/libvlc/util/AndroidUtil.java
+++ b/libvlc/src/org/videolan/libvlc/util/AndroidUtil.java
@@ -22,6 +22,7 @@ package org.videolan.libvlc.util;
import android.net.Uri;
import android.os.Build;
+import android.util.Log;
import java.io.File;
@@ -66,22 +67,28 @@ public class AndroidUtil {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
}
- public static File URItoFile(String URI) {
- if (URI == null) return null;
- return new File(Uri.decode(URI).replaceFirst("file://", ""));
+ public static File UriToFile(Uri uri) {
+ return new File(uri.getPath().replaceFirst("file://", ""));
}
/**
* Quickly converts path to URIs, which are mandatory in libVLC.
*
- * @param path
- * The path to be converted.
+ * @param path The path to be converted.
* @return A URI representation of path
*/
- public static String PathToURI(String path) {
- if (path == null) {
- throw new NullPointerException("Cannot convert null path!");
- }
- return Uri.fromFile(new File(path)).toString();
+ public static Uri PathToUri(String path) {
+ return Uri.fromFile(new File(path));
+ }
+
+ public static Uri LocationToUri(String location) {
+ Uri uri = Uri.parse(location);
+ if (uri.getScheme() == null)
+ throw new IllegalArgumentException("location has no scheme");
+ return uri;
+ }
+
+ public static Uri FileToUri(File file) {
+ return Uri.fromFile(file);
}
}
\ 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 85e555f..afe9ce6 100644
--- a/vlc-android/src/org/videolan/vlc/MediaLibrary.java
+++ b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
@@ -355,7 +355,7 @@ public class MediaLibrary {
// Process the stacked items
for (File file : mediaToScan) {
- String fileURI = AndroidUtil.PathToURI(file.getPath());
+ String fileURI = AndroidUtil.FileToUri(file).toString();
if (mBrowser != null && mBrowser.get() != null)
mBrowser.get().sendTextInfo(file.getName(), count,
mediaToScan.size());
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
index b9c2178..aa08f45 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
@@ -76,7 +76,7 @@ public class AudioUtil {
public static String PLAYLIST_DIR = null;
public static void setRingtone(MediaWrapper song, Context context){
- File newringtone = AndroidUtil.URItoFile(song.getLocation());
+ File newringtone = AndroidUtil.UriToFile(song.getUri());
if(newringtone == null || !newringtone.exists()) {
Toast.makeText(context.getApplicationContext(),context.getString(R.string.ringtone_error), Toast.LENGTH_SHORT).show();
return;
@@ -220,7 +220,7 @@ public class AudioUtil {
}
private static String getCoverFromFolder(MediaWrapper media) {
- File f = AndroidUtil.URItoFile(media.getLocation());
+ File f = AndroidUtil.UriToFile(media.getUri());
if (f == null)
return null;
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 5fccf63..d120e05 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -2696,7 +2696,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
while((bytesRead = is.read(buffer)) >= 0) {
os.write(buffer, 0, bytesRead);
}
- mLocation = AndroidUtil.PathToURI(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY + "/Download/" + filename);
+ mLocation = AndroidUtil.PathToUri(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY + "/Download/" + filename).toString();
}
} catch (Exception e) {
Log.e(TAG, "Couldn't download file from mail URI");
@@ -2715,7 +2715,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
if (cursor != null) {
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
if (cursor.moveToFirst())
- mLocation = AndroidUtil.PathToURI(cursor.getString(column_index));
+ mLocation = AndroidUtil.PathToUri(cursor.getString(column_index)).toString();
cursor.close();
}
// other content-based URI (probably file pickers)
More information about the Android
mailing list