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

Commit dfb94f02 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix ThumbnailUtils thumbnail pts calculation"

parents 1b676f43 0da7cdc1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -800,7 +800,7 @@ public class MediaMetadataRetriever implements AutoCloseable {
     */
    public static final int METADATA_KEY_YEAR            = 8;
    /**
     * The metadata key to retrieve the playback duration of the data source.
     * The metadata key to retrieve the playback duration (in ms) of the data source.
     */
    public static final int METADATA_KEY_DURATION        = 9;
    /**
+6 −4
Original line number Diff line number Diff line
@@ -356,19 +356,21 @@ public class ThumbnailUtils {
                return ImageDecoder.decodeBitmap(ImageDecoder.createSource(raw), resizer);
            }

            // Fall back to middle of video
            final int width = Integer.parseInt(mmr.extractMetadata(METADATA_KEY_VIDEO_WIDTH));
            final int height = Integer.parseInt(mmr.extractMetadata(METADATA_KEY_VIDEO_HEIGHT));
            final long duration = Long.parseLong(mmr.extractMetadata(METADATA_KEY_DURATION));
            // Fall back to middle of video
            // Note: METADATA_KEY_DURATION unit is in ms, not us.
            final long thumbnailTimeUs =
                    Long.parseLong(mmr.extractMetadata(METADATA_KEY_DURATION)) * 1000 / 2;

            // If we're okay with something larger than native format, just
            // return a frame without up-scaling it
            if (size.getWidth() > width && size.getHeight() > height) {
                return Objects.requireNonNull(
                        mmr.getFrameAtTime(duration / 2, OPTION_CLOSEST_SYNC));
                        mmr.getFrameAtTime(thumbnailTimeUs, OPTION_CLOSEST_SYNC));
            } else {
                return Objects.requireNonNull(
                        mmr.getScaledFrameAtTime(duration / 2, OPTION_CLOSEST_SYNC,
                        mmr.getScaledFrameAtTime(thumbnailTimeUs, OPTION_CLOSEST_SYNC,
                        size.getWidth(), size.getHeight()));
            }
        } catch (RuntimeException e) {