[Android] Change how video Uri are handled

Geoffrey Métais git at videolan.org
Fri Nov 7 17:57:47 CET 2014


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Nov  6 22:23:12 2014 +0100| [1d0fbb3f31c3f7e0b388bb3145f00a7b6e56470e] | committer: Geoffrey Métais

Change how video Uri are handled

Allows to read files given through third-party app content provider,
like Archos Media Player, and try the data.getPath() if no content is found..

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=1d0fbb3f31c3f7e0b388bb3145f00a7b6e56470e
---

 .../vlc/gui/video/VideoPlayerActivity.java         |   57 ++++++++++----------
 1 file changed, 30 insertions(+), 27 deletions(-)

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 4b41784..0d30978 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -79,6 +79,7 @@ import android.graphics.PixelFormat;
 import android.media.AudioManager;
 import android.media.AudioManager.OnAudioFocusChangeListener;
 import android.media.MediaRouter;
+import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Environment;
@@ -2101,6 +2102,7 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
         String title = getResources().getString(R.string.title);
         boolean dontParse = false;
         boolean fromStart = false;
+        Uri data;
         String itemTitle = null;
         int itemPosition = -1; // Index in the media list as passed by AudioServer (used only for vout transition internally)
         long intentPosition = -1; // position passed in by intent (ms)
@@ -2108,33 +2110,17 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
         if (getIntent().getAction() != null
                 && getIntent().getAction().equals(Intent.ACTION_VIEW)) {
             /* Started from external application 'content' */
-            if (getIntent().getData() != null
-                    && getIntent().getData().getScheme() != null
-                    && getIntent().getData().getScheme().equals("content")) {
+            data = getIntent().getData();
+            if (data != null
+                    && data.getScheme() != null
+                    && data.getScheme().equals("content")) {
 
-                // Media or MMS URI
-                if(getIntent().getData().getHost().equals("media")
-                        || getIntent().getData().getHost().equals("mms")) {
-                    try {
-                        Cursor cursor = getContentResolver().query(getIntent().getData(),
-                                new String[]{ MediaStore.Video.Media.DATA }, null, null, null);
-                        if (cursor != null) {
-                            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
-                            if (cursor.moveToFirst())
-                                mLocation = LibVLC.PathToURI(cursor.getString(column_index));
-                            cursor.close();
-                        }
-                    } catch (Exception e) {
-                        Log.e(TAG, "Couldn't read the file from media or MMS");
-                        encounteredError();
-                    }
-                }
 
                 // Mail-based apps - download the stream to a temporary file and play it
-                else if(getIntent().getData().getHost().equals("com.fsck.k9.attachmentprovider")
-                       || getIntent().getData().getHost().equals("gmail-ls")) {
+                if(data.getHost().equals("com.fsck.k9.attachmentprovider")
+                       || data.getHost().equals("gmail-ls")) {
                     try {
-                        Cursor cursor = getContentResolver().query(getIntent().getData(),
+                        Cursor cursor = getContentResolver().query(data,
                                 new String[]{MediaStore.MediaColumns.DISPLAY_NAME}, null, null, null);
                         if (cursor != null) {
                             cursor.moveToFirst();
@@ -2142,7 +2128,7 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
                             cursor.close();
                             Log.i(TAG, "Getting file " + filename + " from content:// URI");
 
-                            InputStream is = getContentResolver().openInputStream(getIntent().getData());
+                            InputStream is = getContentResolver().openInputStream(data);
                             OutputStream os = new FileOutputStream(Environment.getExternalStorageDirectory().getPath() + "/Download/" + filename);
                             byte[] buffer = new byte[1024];
                             int bytesRead = 0;
@@ -2158,10 +2144,27 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
                         encounteredError();
                     }
                 }
-
-                // other content-based URI (probably file pickers)
+                // Media or MMS URI
                 else {
-                    mLocation = getIntent().getData().getPath();
+                    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())
+                                mLocation = LibVLC.PathToURI(cursor.getString(column_index));
+                            cursor.close();
+                        }
+                        // other content-based URI (probably file pickers)
+                        else {
+                            mLocation = data.getPath();
+                        }
+                    } catch (Exception e) {
+                        mLocation = data.getPath();
+                        if (!mLocation.startsWith("file://"))
+                            mLocation = "file://"+mLocation;
+                        Log.e(TAG, "Couldn't read the file from media or MMS");
+                    }
                 }
             } /* External application */
             else if (getIntent().getDataString() != null) {



More information about the Android mailing list