Commit 8669233f authored by Finnur Thorarinsson's avatar Finnur Thorarinsson Committed by Commit Bot

[Android] PhotoPicker: Release MediaMetadataRetriever after use.

As per documentation, it should be released as soon as we're
done with it.

Bug: 895776, 656015
Change-Id: Icbdcdb0fb515070d00cde1f7fac52ce1ab594993
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2056811Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Commit-Queue: Finnur Thorarinsson <finnur@chromium.org>
Auto-Submit: Finnur Thorarinsson <finnur@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742138}
parent e7bae43a
......@@ -139,10 +139,11 @@ class DecodeVideoTask extends AsyncTask<List<Bitmap>> {
if (isCancelled()) return null;
AssetFileDescriptor afd = null;
try {
afd = mContentResolver.openAssetFileDescriptor(mUri, "r");
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
// TODO(finnur): Apply try-with-resources to MediaMetadataRetriever once Chrome no longer
// supports versions below Build.VERSION_CODES.N.
MediaMetadataRetriever retriever = null;
try (AssetFileDescriptor afd = mContentResolver.openAssetFileDescriptor(mUri, "r")) {
retriever = new MediaMetadataRetriever();
retriever.setDataSource(afd.getFileDescriptor());
String duration =
retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
......@@ -158,6 +159,7 @@ class DecodeVideoTask extends AsyncTask<List<Bitmap>> {
retriever, afd.getFileDescriptor(), mSize, mFrames, mFullWidth, mIntervalMs);
mDuration = duration;
mRatio = bitmaps.second;
mDecodingResult = DecodingResult.SUCCESS;
return bitmaps.first;
} catch (FileNotFoundException exception) {
mDecodingResult = DecodingResult.FILE_ERROR;
......@@ -165,14 +167,11 @@ class DecodeVideoTask extends AsyncTask<List<Bitmap>> {
} catch (RuntimeException exception) {
mDecodingResult = DecodingResult.RUNTIME_ERROR;
return null;
} catch (IOException exception) {
mDecodingResult = DecodingResult.IO_ERROR;
return null;
} finally {
try {
if (afd != null) afd.close();
mDecodingResult = DecodingResult.SUCCESS;
} catch (IOException exception) {
mDecodingResult = DecodingResult.IO_ERROR;
return null;
}
if (retriever != null) retriever.release();
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment