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

Unverified Commit a32d297c authored by Santiago Seifert's avatar Santiago Seifert Committed by Michael Bestas
Browse files

Handle MediaMetadataRetriever.release IOException

MediaMetadataRetriever.release now declares a thrown IOException.

Bug: 200173116
Test: Should be a non-functional change (only relevant when using MediaDataSource).
Change-Id: I53665e192051ccc5103e9a61014fbed596a86891
parent a9983149
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -179,6 +179,11 @@ public class VideoUtils {
        retrieverSrc.setDataSource(srcPath);
        String degreesString = retrieverSrc.extractMetadata(
                MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
        try {
            retrieverSrc.release();
        } catch (IOException e) {
            // Ignore errors occurred while releasing the MediaMetadataRetriever.
        }
        if (degreesString != null) {
            int degrees = Integer.parseInt(degreesString);
            if (degrees >= 0) {
+8 −3
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.provider.MediaStore.Video.VideoColumns;
import com.android.gallery3d.filtershow.tools.SaveImage.ContentResolverQueryCallback;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

@@ -101,7 +102,7 @@ public class SaveVideoFileUtils {
        values.put(Video.Media.DATE_ADDED, nowInSec);
        values.put(Video.Media.DATA, mDstFileInfo.mFile.getAbsolutePath());
        values.put(Video.Media.SIZE, mDstFileInfo.mFile.length());
        int durationMs = retriveVideoDurationMs(mDstFileInfo.mFile.getPath());
        int durationMs = retrieveVideoDurationMs(mDstFileInfo.mFile.getPath());
        values.put(Video.Media.DURATION, durationMs);
        // Copy the data taken and location info from src.
        String[] projection = new String[] {
@@ -137,7 +138,7 @@ public class SaveVideoFileUtils {
        return contentResolver.insert(Video.Media.EXTERNAL_CONTENT_URI, values);
    }

    public static int retriveVideoDurationMs(String path) {
    private static int retrieveVideoDurationMs(String path) {
        int durationMs = 0;
        // Calculate the duration of the destination file.
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
@@ -147,7 +148,11 @@ public class SaveVideoFileUtils {
        if (duration != null) {
            durationMs = Integer.parseInt(duration);
        }
        try {
            retriever.release();
        } catch (IOException e) {
            // Ignore errors occurred while releasing the retriever.
        }
        return durationMs;
    }

+10 −2
Original line number Diff line number Diff line
@@ -168,7 +168,11 @@ public class VideoSnapshotExt implements IVideoSnapshotListener {
                if (bitmap == null) {
                    Log.w(TAG, "frame cannot be retrieved. ");
                } else {
                    try {
                        retriever.release();
                    } catch (IOException e) {
                        // Ignore errors occurred while releasing the retriever.
                    }
                    if (DEBUG) {
                        Log.d(TAG, "retriever get frame resolution : " +
                                bitmap.getHeight() + "x" + bitmap.getWidth());
@@ -177,7 +181,11 @@ public class VideoSnapshotExt implements IVideoSnapshotListener {
                    return bitmap;
                }
            }
            try {
                retriever.release();
            } catch (IOException e) {
                // Ignore errors occurred while releasing the retriever.
            }
            return null;
        }