Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b537dbaf authored by Dichen Zhang's avatar Dichen Zhang
Browse files

MediaMetadataRetriever.setDataSource(String path): make this method OK to

take URI

External comments:
https://stackoverflow.com/questions/47240026/mediametadataretriever-setdatasource-return-null
MediaMetadataRetriever.setDataSource(String path) can't take URI, whereas same method in MediaPlayer
can, which makes it difficult and confusing for the users.

Bug: 142966190, 141761504
Test: MediaMetadataRetrieverTest
Change-Id: I5ca45cd72b2a77363a49710ed2e578b1de297e40
parent a2cfd6c1
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -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);