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

Commit f664e822 authored by Andreas Gampe's avatar Andreas Gampe Committed by android-build-merger
Browse files

Merge "Frameworks/base: Fix old code in MediaPlayer"

am: 17b069c0

* commit '17b069c0':
  Frameworks/base: Fix old code in MediaPlayer

Change-Id: I5529b6224c747cb9f042520fc707ec78c95b3c9e
parents 3ab9d651 17b069c0
Loading
Loading
Loading
Loading
+8 −12
Original line number Diff line number Diff line
@@ -2446,9 +2446,9 @@ public class MediaPlayer implements SubtitleController.Listener
            throw new IllegalArgumentException("Illegal mimeType for timed text source: " + mime);
        }

        FileDescriptor fd2;
        final FileDescriptor dupedFd;
        try {
            fd2 = Libcore.os.dup(fd);
            dupedFd = Libcore.os.dup(fd);
        } catch (ErrnoException ex) {
            Log.e(TAG, ex.getMessage(), ex);
            throw new RuntimeException(ex);
@@ -2473,7 +2473,6 @@ public class MediaPlayer implements SubtitleController.Listener
            mIndexTrackPairs.add(Pair.<Integer, SubtitleTrack>create(null, track));
        }

        final FileDescriptor fd3 = fd2;
        final long offset2 = offset;
        final long length2 = length;
        final HandlerThread thread = new HandlerThread(
@@ -2483,14 +2482,13 @@ public class MediaPlayer implements SubtitleController.Listener
        Handler handler = new Handler(thread.getLooper());
        handler.post(new Runnable() {
            private int addTrack() {
                InputStream is = null;
                final ByteArrayOutputStream bos = new ByteArrayOutputStream();
                try {
                    Libcore.os.lseek(fd3, offset2, OsConstants.SEEK_SET);
                    Libcore.os.lseek(dupedFd, offset2, OsConstants.SEEK_SET);
                    byte[] buffer = new byte[4096];
                    for (long total = 0; total < length2;) {
                        int bytesToRead = (int) Math.min(buffer.length, length2 - total);
                        int bytes = IoBridge.read(fd3, buffer, 0, bytesToRead);
                        int bytes = IoBridge.read(dupedFd, buffer, 0, bytesToRead);
                        if (bytes < 0) {
                            break;
                        } else {
@@ -2504,15 +2502,13 @@ public class MediaPlayer implements SubtitleController.Listener
                    Log.e(TAG, e.getMessage(), e);
                    return MEDIA_INFO_TIMED_TEXT_ERROR;
                } finally {
                    if (is != null) {
                    try {
                            is.close();
                        } catch (IOException e) {
                        Libcore.os.close(dupedFd);
                    } catch (ErrnoException e) {
                        Log.e(TAG, e.getMessage(), e);
                    }
                }
            }
            }

            public void run() {
                int res = addTrack();