[Android] Add MediaUtils.getContentMediaUri util method
Geoffrey Métais
git at videolan.org
Fri Apr 15 12:01:06 CEST 2016
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Apr 14 12:21:30 2016 +0200| [01439c1cef7843d3e25b067f2a1fe8ef830790d0] | committer: Geoffrey Métais
Add MediaUtils.getContentMediaUri util method
> https://code.videolan.org/videolan/vlc-android/commit/01439c1cef7843d3e25b067f2a1fe8ef830790d0
---
.../src/org/videolan/vlc/StartActivity.java | 17 +----------------
.../src/org/videolan/vlc/media/MediaUtils.java | 22 ++++++++++++++++++++++
2 files changed, 23 insertions(+), 16 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/StartActivity.java b/vlc-android/src/org/videolan/vlc/StartActivity.java
index a23da29..818f4c7 100644
--- a/vlc-android/src/org/videolan/vlc/StartActivity.java
+++ b/vlc-android/src/org/videolan/vlc/StartActivity.java
@@ -108,22 +108,7 @@ public class StartActivity extends Activity {
}
// Media or MMS URI
else if (TextUtils.equals(data.getAuthority(), "media")){
- try {
- Cursor cursor = getContentResolver().query(data,
- new String[]{ MediaStore.Video.Media.DATA }, null, null, null);
- if (cursor != null) {
- int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
- if (cursor.moveToFirst())
- mUri = AndroidUtil.PathToUri(cursor.getString(column_index));
- cursor.close();
- } else // other content-based URI (probably file pickers)
- mUri = data;
- } catch (Exception e) {
- mUri = data;
- if (mUri.getScheme() == null)
- mUri = AndroidUtil.PathToUri(mUri.getPath());
- Log.e(TAG, "Couldn't read the file from media or MMS");
- }
+ mUri = MediaUtils.getContentMediaUri(data);
} else {
ParcelFileDescriptor inputPFD;
try {
diff --git a/vlc-android/src/org/videolan/vlc/media/MediaUtils.java b/vlc-android/src/org/videolan/vlc/media/MediaUtils.java
index cb51899..bf2418e 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaUtils.java
+++ b/vlc-android/src/org/videolan/vlc/media/MediaUtils.java
@@ -4,9 +4,12 @@ import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.database.Cursor;
import android.net.Uri;
+import android.provider.MediaStore;
import android.support.v4.content.LocalBroadcastManager;
+import org.videolan.libvlc.util.AndroidUtil;
import org.videolan.vlc.PlaybackService;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
@@ -144,6 +147,25 @@ public class MediaUtils {
return title;
}
+ public static Uri getContentMediaUri(Uri data) {
+ Uri uri = null;
+ try {
+ Cursor cursor = VLCApplication.getAppContext().getContentResolver().query(data,
+ new String[]{ MediaStore.Video.Media.DATA }, null, null, null);
+ if (cursor != null) {
+ int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
+ if (cursor.moveToFirst())
+ uri = AndroidUtil.PathToUri(cursor.getString(column_index));
+ cursor.close();
+ } else // other content-based URI (probably file pickers)
+ uri = data;
+ } catch (Exception e) {
+ uri = data;
+ if (uri.getScheme() == null)
+ uri = AndroidUtil.PathToUri(uri.getPath());
+ }
+ return uri != null ? uri : data;
+ }
private static String getMediaString(Context ctx, int id) {
if (ctx != null)
return ctx.getResources().getString(id);
More information about the Android
mailing list