From d504ab14d264e340fac9422b84b5f3c677d87c5f Mon Sep 17 00:00:00 2001 From: Lajos Molnar Date: Mon, 18 Aug 2014 14:26:55 -0700 Subject: [PATCH] media.MediaPlayer: don't check file-existence for URI-s with scheme setDataSource can be called with URI-s as well as with file paths. Check file-existence only for file:// URI-s as well as URI-s without scheme (which are assumed to be paths). Bug: 17109022 Change-Id: I70f16a4f614dcef0b47fa264cf708473036cef4e --- media/java/android/media/MediaPlayer.java | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/media/java/android/media/MediaPlayer.java b/media/java/android/media/MediaPlayer.java index 2fa0c931e84cf..7c3b4fc1e1346 100644 --- a/media/java/android/media/MediaPlayer.java +++ b/media/java/android/media/MediaPlayer.java @@ -1049,8 +1049,17 @@ public class MediaPlayer implements SubtitleController.Listener private void setDataSource(String path, String[] keys, String[] values) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException { final Uri uri = Uri.parse(path); - if ("file".equals(uri.getScheme())) { + final String scheme = uri.getScheme(); + if ("file".equals(scheme)) { path = uri.getPath(); + } else if (scheme != null) { + // handle non-file sources + nativeSetDataSource( + MediaHTTPService.createHttpServiceBinderIfNecessary(path), + path, + keys, + values); + return; } final File file = new File(path); @@ -1060,20 +1069,10 @@ public class MediaPlayer implements SubtitleController.Listener setDataSource(fd); is.close(); } else { - _setDataSource(path, keys, values); + throw new IOException("setDataSource failed."); } } - private void _setDataSource( - String path, String[] keys, String[] values) - throws IOException, IllegalArgumentException, SecurityException, IllegalStateException { - nativeSetDataSource( - MediaHTTPService.createHttpServiceBinderIfNecessary(path), - path, - keys, - values); - } - private native void nativeSetDataSource( IBinder httpServiceBinder, String path, String[] keys, String[] values) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException;