Fixes a crash when a thumbnail for an image attachment fails to load.

This commit is contained in:
Vavassor 2017-07-19 00:28:36 -04:00
parent 2674a11c50
commit e24dcbbd7c

View File

@ -1365,6 +1365,10 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
MediaMetadataRetriever retriever = new MediaMetadataRetriever(); MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(this, uri); retriever.setDataSource(this, uri);
Bitmap source = retriever.getFrameAtTime(); Bitmap source = retriever.getFrameAtTime();
if (source == null) {
displayTransientError(R.string.error_media_upload_opening);
return;
}
Bitmap bitmap = ThumbnailUtils.extractThumbnail(source, THUMBNAIL_SIZE, THUMBNAIL_SIZE); Bitmap bitmap = ThumbnailUtils.extractThumbnail(source, THUMBNAIL_SIZE, THUMBNAIL_SIZE);
source.recycle(); source.recycle();
addMediaToQueue(QueuedMedia.Type.VIDEO, bitmap, uri, mediaSize); addMediaToQueue(QueuedMedia.Type.VIDEO, bitmap, uri, mediaSize);
@ -1378,8 +1382,12 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
displayTransientError(R.string.error_media_upload_opening); displayTransientError(R.string.error_media_upload_opening);
return; return;
} }
Bitmap source = BitmapFactory.decodeStream(stream); Bitmap source = BitmapFactory.decodeStream(stream);
if (source == null) {
IOUtils.closeQuietly(stream);
displayTransientError(R.string.error_media_upload_opening);
return;
}
Bitmap bitmap = ThumbnailUtils.extractThumbnail(source, THUMBNAIL_SIZE, THUMBNAIL_SIZE); Bitmap bitmap = ThumbnailUtils.extractThumbnail(source, THUMBNAIL_SIZE, THUMBNAIL_SIZE);
source.recycle(); source.recycle();
try { try {