Merge "MediaMetadataRetriever.setDataSource(String path): make this method OK to take URI"

This commit is contained in:
Dichen Zhang
2019-10-31 17:18:17 +00:00
committed by Android (Google) Code Review

View File

@@ -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<String, String>());
return;
}
try (FileInputStream is = new FileInputStream(path)) {
FileDescriptor fd = is.getFD();
setDataSource(fd, 0, 0x7ffffffffffffffL);