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

Commit a0a955f8 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Set MediaPlayer sources in more direct fashion.

As part of the isolated storage work in Q, some filesystem paths
don't actually exist.  It's safer to simply try opening the file
and let FileInputStream throw a FileNotFoundException.

This change results in more descriptive errors to developers,
without changing the behavior of throwing an IOException if the
file doesn't exist.

Bug: 124208701
Test: manual
Change-Id: I4710a55431d8dc6cb96561f551b34892d8c15ba5
parent 55a17dca
Loading
Loading
Loading
Loading
+5 −16
Original line number Diff line number Diff line
@@ -1180,13 +1180,8 @@ public class MediaPlayer extends PlayerBase
        }

        final File file = new File(path);
        if (file.exists()) {
            FileInputStream is = new FileInputStream(file);
            FileDescriptor fd = is.getFD();
            setDataSource(fd);
            is.close();
        } else {
            throw new IOException("setDataSource failed.");
        try (FileInputStream is = new FileInputStream(file)) {
            setDataSource(is.getFD());
        }
    }

@@ -2868,15 +2863,9 @@ public class MediaPlayer extends PlayerBase
            throw new IllegalArgumentException(msg);
        }

        File file = new File(path);
        if (file.exists()) {
            FileInputStream is = new FileInputStream(file);
            FileDescriptor fd = is.getFD();
            addTimedTextSource(fd, mimeType);
            is.close();
        } else {
            // We do not support the case where the path is not a file.
            throw new IOException(path);
        final File file = new File(path);
        try (FileInputStream is = new FileInputStream(file)) {
            addTimedTextSource(is.getFD(), mimeType);
        }
    }