diff --git a/media/java/android/media/MediaMetadataRetriever.java b/media/java/android/media/MediaMetadataRetriever.java index cc5ddeb49813d..5d2bdd756840d 100644 --- a/media/java/android/media/MediaMetadataRetriever.java +++ b/media/java/android/media/MediaMetadataRetriever.java @@ -34,6 +34,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -62,7 +63,8 @@ public class MediaMetadataRetriever implements AutoCloseable { * method before the rest of the methods in this class. This method may be * time-consuming. * - * @param path The path of the input media file. + * @param path The path, or the URI (doesn't support streaming source currently) + * of the input media file. * @throws IllegalArgumentException If the path is invalid. */ public void setDataSource(String path) throws IllegalArgumentException { @@ -70,6 +72,15 @@ public class MediaMetadataRetriever implements AutoCloseable { throw new IllegalArgumentException("null path"); } + final Uri uri = Uri.parse(path); + final String scheme = uri.getScheme(); + if ("file".equals(scheme)) { + path = uri.getPath(); + } else if (scheme != null) { + setDataSource(path, new HashMap()); + return; + } + try (FileInputStream is = new FileInputStream(path)) { FileDescriptor fd = is.getFD(); setDataSource(fd, 0, 0x7ffffffffffffffL);