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

Commit 24a38f1a authored by James Dong's avatar James Dong
Browse files

Switch to use MediaMetadataRetriever to generate the project thumbnail when...

Switch to use MediaMetadataRetriever to generate the project thumbnail when the first media item is a MediaVideoItem

o This patch allows us to use the logic from MediaMetadataRetriever to extract a thumbnail instead of extracting
  the thumbnail from a fixed position (@500 ms).

Change-Id: I81e8378d9bed80894cc622479679021dce3d52e5
related-to-bug: 3485609
parent 93aa58fd
Loading
Loading
Loading
Loading
+27 −6
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.graphics.Bitmap;
import android.graphics.Rect;
import android.media.videoeditor.MediaImageItem;
import android.media.videoeditor.MediaItem;
import android.media.MediaMetadataRetriever;
import android.util.Log;
import android.util.Xml;
import android.view.Surface;
@@ -1833,12 +1834,32 @@ public class VideoEditorImpl implements VideoEditor {
            }

            Bitmap projectBitmap = null;
            String filename = mI.getFilename();
            if (mI instanceof MediaVideoItem) {
                MediaMetadataRetriever retriever = new MediaMetadataRetriever();
                retriever.setDataSource(filename);
                Bitmap bitmap = retriever.getFrameAtTime();
                retriever.release();
                retriever = null;
                if (bitmap == null) {
                    String msg = "Thumbnail extraction from " +
                                    filename + " failed";
                    throw new IllegalArgumentException(msg);
                }
                // Resize the thumbnail to the target size
                projectBitmap =
                    Bitmap.createScaledBitmap(bitmap, width, height, true);
            } else {
                try {
                    projectBitmap = mI.getThumbnail(width, height, 500);
                } catch (IllegalArgumentException e) {
                throw new IllegalArgumentException ("Illegal argument error creating project thumbnail");
                    String msg = "Project thumbnail extraction from " +
                                    filename + " failed";
                    throw new IllegalArgumentException(msg);
                } catch (IOException e) {
                throw new IllegalArgumentException ("IO Error creating project thumbnail");
                    String msg = "IO Error creating project thumbnail";
                    throw new IllegalArgumentException(msg);
                }
            }

            try {