[Android] [PATCH] Change how video Uri are handled
Geoffrey Métais
geoffrey.metais at gmail.com
Fri Nov 7 11:00:06 CET 2014
Slight modification in } catch (Exception e) { block, to ensure dumb Uri
starting with content:/ and containing a file path are handled.
Because getContentResolver().query(..) throws an exception in this case.
On Fri, Nov 7, 2014 at 10:56 AM, Geoffrey Métais <geoffrey.metais at gmail.com>
wrote:
> 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..
> ---
> .../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) {
> --
> 1.9.1
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/android/attachments/20141107/fc151800/attachment.html>
More information about the Android
mailing list